2
//Add Row with No data recorded message, when the table is empty/////////////////////////////////////////////

    $("tbody").each(function () {
        NoOfColumns = $(this).prev("thead").find("th").length;

        if ($(this).is(":empty")) {
            $(this).append("<tr><td  class='trTopItem' style='border-top:1px solid silver;background-color:#eeeaf3;'  colspan=" + NoOfColumns + ">No Data Recorded</td></tr>");
        }
    });

Any help would be apreciated, thanks.

3
  • Have you tried using Chrome's developer tools to debug? Is it hitting the if statement, is that evaluating to true etc etc
    – Psytronic
    Nov 4, 2010 at 9:40
  • I am trying but it goes to the jquery.min.js and I get lost. Thanks for the tip tho
    – Amra
    Nov 4, 2010 at 9:46
  • Lopez: for debugging you can use the non-minified version of jquery. Its not too hard to understand and its good to see exactly what is happening if you are getting confused. Whether it would have helped in this case or not I don't know since cross browser stuff can be tricky to get just by looking at the script. Its a useful general trick though. :)
    – Chris
    Nov 4, 2010 at 9:59

1 Answer 1

3

I suspect it is to do with what the browsers consider to be empty elements. If you look at the example I've cretaed with jsfiddle you'll notice that the first two tables differ only on the fact that one of teh tbody elements has whitespace and the other doesn't.

http://jsfiddle.net/qtjdp/1/

On IE this renders the no data message in both and on firefox only on the one with no whitespace in the tag.

You'll see I have put in an alternative if statement that is currently commented out. If you use this it works on firefox (and Psytronic tells me in comments Chrome too though I don't have that installed):

if ($(this).children().length==0)

The reason is that this is checking for child elements (which is what you want here), not just content of any kind.

3
  • Works the same on Chrome as on FF
    – Psytronic
    Nov 4, 2010 at 9:50
  • Wow, That is a great explanation, Thank you very much. +1 :-)
    – Amra
    Nov 4, 2010 at 9:50
  • @Psytronic: thanks for checking. I thought it would since the two are pretty similar in terms of scripting usually but its nice to confirm. :)
    – Chris
    Nov 4, 2010 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.