Getting the row count in the ondatabound event

3 posts, 1 answers
  1. Carrie
    Carrie avatar
    27 posts
    Member since:
    Aug 2013

    Posted 04 Sep 2013 Link to this post


    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:
        .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);
        .Filterable(filterable => filterable
          .Operators(operators => operators
                              .ForString(str => str.Clear()
                              .StartsWith("Starts with")
                              .IsEqualTo("Is equal to")
                              .IsNotEqualTo("Is not equal to")))
       .Selectable(selectable => selectable
       .DataSource(dataSource => dataSource
                   .Read(read => read.Action("Get", "Grid", new {showAll = ViewBag.ShowAll}))
       .Events(e => e.Change("onChanged").DataBound("onDataBound"))
  2. Answer
    Dimo avatar
    8443 posts

    Posted 05 Sep 2013 Link to this post

    Hello Carrie,

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

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Carrie
    Carrie avatar
    27 posts
    Member since:
    Aug 2013

    Posted 05 Sep 2013 Link to this post

    Okay thanks, got it working:

    function onDataBound(arg) {
    var cnt = $('#Grid').data('kendoGrid');
Back to Top