Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KendoUI grid - turning pagination on / off programmatically

I would like pagination to show only if I have more records than my pageSize. Is there any way to achieve this affect?

Ideally as data is added/removed on the client the pagination mechanism would show/hide accordingly (again, only displaying if there are more items than the pagesize).

Any ideas/workarounds?

Update

The answer provided by j4ro seems to work great once I removed the height setting code. It was not necessary for me, but your mileage may vary as I didn't test this with a more typical use-case.

dataBound: function () {
    if (this.dataSource.totalPages() === 1) {
        this.pager.element.hide();
    }
    else {
        this.pager.element.show();
    }
}
like image 587
Shaun Rowan Avatar asked Jan 20 '14 05:01

Shaun Rowan


1 Answers

Add this function to your grid on dataBound event:

dataBound: function () {
        var gridContent = this.element.find('.k-grid-content');
        if (this.dataSource.totalPages() === 1) {
            gridContent.css('height', gridContent.height() + this.pager.element.innerHeight());
            this.pager.element.hide();
        }
        else {
            this.pager.element.show();
            gridContent.css('height', gridContent.height() - this.pager.element.innerHeight());
        }
    }
like image 192
Jarosław Kończak Avatar answered Sep 18 '22 13:09

Jarosław Kończak