Disable paging when only 1 page

4 posts, 0 answers
  1. Lennart
    Lennart avatar
    5 posts
    Member since:
    Jan 2013

    Posted 10 Jan 2013 Link to this post

    Hi all,

    I was wondering if it was possible to disable/hide the paging feature dynamically when only 1 page is shown, i.e. PageSize is set to 100, but the data only consists of 70 rows.

    Thanks!

    Lennart
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 14 Jan 2013 Link to this post

    Hello Lennart,

    You can hide the pager when total pages in the data source is one. For example:
    //get reference to the Grid
    var grid = $(".k-grid").data("kendoGrid");
     
    grid.bind("dataBound", function() {
     if (this.dataSource.totalPages() == 1) {
      this.pager.element.hide();
     }
    });


    Regards,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Lennart
    Lennart avatar
    5 posts
    Member since:
    Jan 2013

    Posted 14 Jan 2013 Link to this post

    Hi,

    The solution you proposed did not work for me, but thanks for helping me get on my way. I ended up doing this:

    In the grid definition:
    .Events(events => events
      .DataBound("GridDataBound")
    )
    And then in JavaScript:
    function GridDataBound() {
        if (this.dataSource.totalPages() == 1) {
            this.pager.element.hide();
        }
    }
    Thanks again!
  5. Timothy
    Timothy avatar
    3 posts
    Member since:
    Mar 2016

    Posted 26 Aug Link to this post

    A much cleaner fix that doesn't need any javascript at all - use this css. This basically just hides the page number if it's the only one on the page.

    .k-pager-numbers li:nth-child(2):last-child { display:none; }
Back to Top
UI for ASP.NET MVC is VS 2017 Ready