Shaun Rowan
Shaun Rowan

Reputation: 9539

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();
    }
}

Upvotes: 6

Views: 5748

Answers (1)

Jarosław Kończak
Jarosław Kończak

Reputation: 3407

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());
        }
    }

Upvotes: 7

Related Questions