setting row colors for XML Island Table

honkinberry
honkinberry used Ask the Experts™
on
I've got an XML Data Island, that is sourced to a table.  I need to set the row colors based on one of the field values.  My code works correctly, but it keeps getting called before the entire table is rendered (seems the XMLDocument is loaded, recordset state is set to 4, and *then* the table is rendered, with no apparent events to intercept).  If I call the code from body.onmouseover, or a button click event, or even throw in an alert statement to ^pause^ the code for just a second, the table renders and then the colors get set.  I've been trying to set up a while loop to wait until the table's row count is the same as the recordset's, but haven't been having any luck with that either.  Best of luck!

So I've got this:
      function requery () {
            attendees.XMLDocument.load("https://server.com?value=" + parent.selectbox.value);
            // NEED TO PAUSE here to wait until table is rendered
            // alert("hi there"); // will make everything work
            var i = 0;
            var oForm = document.forms[i];
            while (oForm != null) {
                  if (oForm.name == "attinfo") {
                        var oTR = oForm.parentElement;
                        var colorx = getbackcolor(oForm.atttype.value); // returns 1 of 4 possible colors
                        oTR.style.backgroundColor = colorx;
                  } // if
            i++;
            oForm = document.forms[i];
            } // while
      } // requery

...

      <xml id=attendees></xml> <script language="Javascript">attendees.async=false;</script>

...

      <TABLE id="attendee_table" datasrc="#attendees">
      <tr>
            <form name="attinfo">
                  <input type="hidden" name="attendno" datafld="attendno">
                  <input type="hidden" name="atttype" datafld="atttype"> <!-- for setting color of row -->

                  <td>
                        ...
                  </td>

                  ...

            </form>
      </tr>
      </TABLE>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Can you send me that source code?

I can modifiy and send it back to you.

Probably you put that javascript at the end of "<TABLE>".

If no solution yet you send me your code.

Thanks,
Sachi

Author

Commented:
hey, so here's the latest news, this is rather unusual and fun.

If one was to modify the XML island to load it's data at document load, then the body onload handler fires *after* the table is rendered.  This runs contrary to if you use Javascript to load XML content, the bound table will still be rendering when your formatting code is running.  So my modified code looks more like this:

    // same function, just not reloading the XML content, so its name is now appropriately changed.
    function applyStyle () {
         var i = 0;
         var oForm = document.forms[i];
         while (oForm != null) {
              if (oForm.name == "attinfo") {
                   var oTR = oForm.parentElement;
                   var colorx = getbackcolor(oForm.atttype.value); // returns 1 of 4 possible colors
                   oTR.style.backgroundColor = colorx;
              } // if
         i++;
         oForm = document.forms[i];
         } // while
    } // applyStyle

...

    <!-- we now set the xml island to load its content at document load, so that the body onload handler works for us -->
    <xml id=attendees></xml>
        <script language="Javascript">
            attendees.src="https://server.com/methodthatreturnsxml?" + parent.select.value;
            attendees.async=false;
        </script>

...

    <!-- this onload handler doesn't fire until *after* the bound table is rendered -->
    <body onload="applyStyle()">

    <TABLE id="attendee_table" datasrc="#attendees">
    <tr>
         <form name="attinfo">
              <input type="hidden" name="attendno" datafld="attendno">
              <input type="hidden" name="atttype" datafld="atttype"> <!-- for setting color of row -->

              <td>
                   ...
              </td>

              ...

         </form>
    </tr>
    </TABLE>


SO, pretty interesting, isn't it?  I guess the moral of the story is that if you have a table bound to an XML island, and that table has any unique styling to it, you should have the XML load with the document, rather than try to save some bandwidth and use Javascript to reload the changing data.  Of course this does mean that you'll lose some of the coolness of using XML islands in that you take the hit on content transfer, as well as the look of not having the entire screen refresh (but my table is inside an IFRAME, so the page content is minimal, as is the effect of refreshing).

STILL interested in a more elegant way to do this, if anybody else has yet another fancy way to do this.  I gotta give out these points to someone!  :)
Commented:
PAQed with points refunded (250)

modulo
Community Support Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial