This is a migrated thread and some comments may be shown as answers.

Grid Row Count

3 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 1
Robert asked on 28 Feb 2012, 11:47 PM
Is there a way to get the # of rows in a grid using javascript?

3 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 29 Feb 2012, 11:20 AM
Hi Robert,

You can use the following statement in your code to get the number of rows:
$('#Grid').data('tGrid').data.length


All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Robert
Top achievements
Rank 1
answered on 29 Feb 2012, 05:52 PM
Thanks Petur. I must still be doing something wrong.

I have this script that should fire on the OnComplete event. The goal is to hide the Add toolbar button when the number of items in the grid is == the total # of available items that can be added. But when I run it, the grid doesn't load any records. If I hard-code a # in, it works, but when I try to use the grid record count using the tip you gave me, they don't.

@section HeadContent {
<script type="text/javascript">
    function grid_loaded(args) {
        if ("@ViewBag.TotalRoles" == $('#Roles').data('tGrid').data.length) {
            $('.t-grid-add').hide();
        } else {
            $('.t-grid-add').show();
        }
    };
</script>

0
Robert
Top achievements
Rank 1
answered on 29 Feb 2012, 06:19 PM
I can be such a noob sometimes. Can you tell I am not a javascript programmer? Corrected version below - and it works. The only quibble I have is that instead of getting a count of all rows coming back in the AJAX select, I am only getting the number actually displayed/paged.

For now I will work around that by turning paging off on this particular grid.

<script type="text/javascript">
    function grid_loaded(e) {
        var noOfRecords = $(this).data('tGrid').data.length;
        if ("123" == noOfRecords) {
           $('.t-grid-add').hide();
        } else {
           $('.t-grid-add').show();
        }
    };
</script>
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Robert
Top achievements
Rank 1
Share this question
or