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

Getting the row count in the ondatabound event

2 Answers 1352 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carrie
Top achievements
Rank 1
Carrie asked on 04 Sep 2013, 06:45 PM
Hello,

I am wondering how I can get the total rowcount while inside the ondatabound event ?   

Here is the background of why I am looking for this info.   I am trying to code in a row cap lets say of 250 records which will be done in the controller.  However I have a requirement that if the query was capped I need to offer the user an option to view all the rows.   Basically implementing an alert to the user that they ran a query that returns a large set of data.   At first they will only get the 250 rows but they are given an option to return all rows like a button or something which would rebind the grid and grab all rows from the controller.

I am sending a parameter in the Action call to bind that specifies whether or not to show all records, but I need to figure out how to get a row count so I know if the initial databind hit the cap. 

Here is my code:
@(Html.Kendo().Grid(Model)   
    .Name("Grid")
    .HtmlAttributes(new { style = "font-size:.85em;" })
    .Columns(columns =>
    {
        columns.Bound(p => p.Id).Width(60);
        columns.Bound(p => p.Title).Width(250);
        columns.Bound(p => p.AssignedUser).Width(120);
        })
    .Pageable()
    .Groupable()
    .Sortable()
    .Filterable(filterable => filterable
      .Extra(false)
      .Operators(operators => operators
                          .ForString(str => str.Clear()
                          .StartsWith("Starts with")
                          .Contains("Contains")
                          .IsEqualTo("Is equal to")
                          .IsNotEqualTo("Is not equal to")))
      )
   .Selectable(selectable => selectable
      .Mode(GridSelectionMode.Single))
   .DataSource(dataSource => dataSource
               .Ajax()
               .Read(read => read.Action("Get", "Grid", new {showAll = ViewBag.ShowAll}))
               )
   .Events(e => e.Change("onChanged").DataBound("onDataBound"))
)

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 05 Sep 2013, 07:44 AM
Hello Carrie,

You can use the total() method of the Grid dataSource.

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Carrie
Top achievements
Rank 1
answered on 05 Sep 2013, 11:09 AM
Okay thanks, got it working:

function onDataBound(arg) {
var cnt = $('#Grid').data('kendoGrid').dataSource.total();
alert(cnt);
}
Tags
Grid
Asked by
Carrie
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Carrie
Top achievements
Rank 1
Share this question
or