0

What is considered the best practice for determining whether there are any rows bound?

Currently, I'm using the client-side OnDataBound event, and code similar to the following:

gridDataBound: function (event)
{
   var rows = $('tbody tr:has(td)', this);
   if (rows.length == 0 || (rows.length == 1 && rows[0].innerText == "No records to display'))
      $('#GridSection').hide("slow");
}

There has got to be a better way!

3 Answers 3

1

I can suggest a shorter version:

 if ($(this).find(".t-no-data").length) {
    $("#GridSection").hide("slow");
 }
Sign up to request clarification or add additional context in comments.

Comments

0

Ah, a few minutes poking around and I think I have a solution that really feels better-

if ($("tbody tr:has(td).t-no-data", this).length != 0) {
   $("#GridSection").hide("slow");
}

Comments

0

$('#grid-name').data('tGrid').data is an array of all of the records.

So, you can get the number of records using:

$('#grid-name').data('tGrid').data.length;

1 Comment

unless there are no records. in that case, data is undefined

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.