knockout js Datasource pagination

HTML Table Pagination using Knockout JS


function getAnimals() {
    var params = {
        limit: this.pager.limit(),
        startIndex: this.pager.limit() * (this.pager.page() - 1)
    };

    $.ajax({
        type: 'POST',
        url: '/echo/json/',
        data: {
            json: ko.toJSON(initialData.slice(params.startIndex, params.startIndex + params.limit))
        },
        context: this,
        success: function (data) {
            this(data);
            this.pager.totalCount(100);
        },
        dataType: 'json'
    });
};

var viewModel = {
    items: ko.observableArray([]).extend({
        datasource: getAnimals,
        pager: {
            limit: 10
        }
    })
};

ko.applyBindings(viewModel);
DEMO
knockout js Datasource pagination knockout js Datasource pagination Reviewed by Bhaumik Patel on 9:05 PM Rating: 5