Pejman
Pejman

Reputation: 3964

Server paging in Knockout-Kendo Grid bound to local (server-filled) ko.observableArray property in viewmodel

I am using Knockout-Kendo.js library for my js + HTML5 SPA. In my viewmodel I have a myItems Knockout Observable Array. I have a client-side repository that is responsible for getting data from server and keeping it. I want to be able to fill myItems in my viewmodel based on a POST request to an API that sends a filter object (containing filters and paging info) to server and returns a list of filtered items.

Upvotes: 2

Views: 2521

Answers (2)

Vicky
Vicky

Reputation: 829

dataSource: { pageSize: 20 } specify like this.... if u mention only pageSize: 20 like this ,it doesn't works

Upvotes: 0

RP Niemeyer
RP Niemeyer

Reputation: 114792

You can actually use a dataSource directly if you need to in Knockout-Kendo. If you specify the data option with either false or {} and then specify the dataSource option as well, then it will use it.

For example, you could bind it like:

<div data-bind="kendoGrid: gridOptions"></div>

With a view model:

var grid = {
  data: false,
  dataSource: {
    type: "odata",
    transport: {
      read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
    },
    schema: {
      model: {
        fields: {
          OrderID: {
            type: "number"
          },
          Freight: {
            type: "number"
          },
          ShipName: {
            type: "string"
          },
          OrderDate: {
            type: "date"
          },
          ShipCity: {
            type: "string"
          }
        }
      }
    },
    pageSize: 50,
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true
  },
  height: 250,
  sortable: true,
  pageable: true,
  columns: [{
    field: "OrderID",
    filterable: false
  },
    "Freight", {
    field: "OrderDate",
    title: "Order Date",
    width: 100,
    format: "{0:MM/dd/yyyy}"
  }, {
    field: "ShipName",
    title: "Ship Name",
    width: 200
  }, {
    field: "ShipCity",
    title: "Ship City"
  }]
};

ko.applyBindings({
  gridOptions: grid
});

Sample here: http://jsfiddle.net/rniemeyer/shwrb/

Upvotes: 2

Related Questions