1

Making my first post here to get feedback on a particular solution to a problem that I dealt with yesterday. I came up with something that solves my problem and achieves the effect desired but I think that at best it's an inelegant solution and at worst an ugly hack.

The problem: How can I re-order four div's on a page that are hard-coded in a specific order on the page. The goal: a method of quickly re-ordering these blocks based on client preference.

The constraints: I can't touch the markup except to add a classes and ids or wrappers (I can't re-structure the html at all). This is for an existing, working, product that is already in use by several different clients.

Here is the markup with content removed:

<!-- content-panel 2 -->
<div id="home-messages-box" class="content-panel">
    <table cellspacing="0">
        <tr>
            <td class="tableCaption">
            </td>
        </tr>
    </table>
    <table class="tableContent" cellpadding="0" cellspacing="0">
        <tr>
            <td>
            </td>
        </tr>
    </table>
</div>

<!-- content-panel 3 -->
<div id="home-programs-box" class="content-panel">
    <table cellspacing="0">
        <tr>
        </tr>
    </table>
    <table class="tableContent" cellpadding="3" cellspacing="3">
        <tr>
            <td>
            </td>
        </tr>
    </table>
</div>

<!-- content-panel 4 -->
<div id="home-actionitems-box" class="content-panel">
    <table cellspacing="0">
        <tr>
            <td class="tableCaption">
            </td>
        </tr>
    </table>
    <table class="tableContent" cellpadding="0" cellspacing="0">
        <tr>
            <td>
            </td>
        </tr>
        <tr>
            <td>
            </td>
        </tr>
    </table>
</div>
</div><!-- content-panel-wrapper -->

And here is the jQuery I'm using to re-order those Divs after the page loads:

$(function () { 
    $("#home-actionitems-box").appendTo("#content-panel-wrapper");
    $("#home-welcome-box").appendTo("#content-panel-wrapper");
    $("#home-messages-box").appendTo("#content-panel-wrapper");
    $("#home-programs-box").appendTo("#content-panel-wrapper");
});

Is there an easier, more elegant way to do this? I accept that it is probably a hacky solution to an inflexible structure that is the result of no UI/UX design thinking at the beginning of the project (years ago). But I am interested in the opinion of other people who sometimes have to come up with inelegant solutions to problems like this.

Judah
  • 106
  • 8
  • You can also use prependTo to add to the beginning. I think what you have is a pretty good solution. – jamesfzhang Oct 20 '11 at 17:25
  • Is there any reason why you can't simply reposition those div's with per client css? – Jesse Oct 20 '11 at 17:25
  • Where do you get the order of the DIV's from, if they are chosen by the client? Cause otherwise a sort function defined by the order would in my opinion be better and more flexible. – Marco Johannesen Oct 20 '11 at 17:37
  • Jesse: Yes I did try to use CSS first, but found it to be too limiting because each div fills the horizontal space, so absolute positioning is the only way to move them around. But each div also must be free to grow vertically (no set height) and I can't anticipate when a div might start to overlap one underneath it. – Judah Oct 20 '11 at 17:44
  • Marco: Do you know of an example of something like that? DIV order will supposedly come from some of the clients who aren't happy with the default order of the div's. Such as one client who has requested the the "messages box" be located at the bottom of the screen. I did propose creating our own custom sort on a per-client basis but it wasn't very popular because it seemed pretty time-consuming, and it's a little out of my wheelhouse so I couldn't defend it without knowing more about it, which kept me at the above solution. – Judah Oct 20 '11 at 17:57
  • Ok. But do you store their "choices" in the database, or do you code their soloution after it? :) – Marco Johannesen Oct 20 '11 at 18:00
  • Yes good question. We are not storing the choices in the database because that would also require too much development time to complete during this sprint. But that would be a better way to have set it up from the beginning, right? – Judah Oct 20 '11 at 18:02

0 Answers0