query

Executes the specified query over the data items. Makes an HTTP request if bound to a remote service.

This method is useful when you need to modify several parameters of the data request at the same time (e.g. filtering and sorting). If you execute filter() and then sort(), the DataSource will make two separate requests. With query(), it will make one request.

This method will remove the current sort, filter, group, aggregates descriptors and paging information, if such are not provided as arguments.

Parameters

options Object (optional)

The query options which should be applied.

options.aggregate Array (optional)

The aggregate configuration. Accepts the same values as the aggregate option. The query method will request the remote service if the serverAggregates option is set to true.

options.filter Object|Array (optional)

The filter configuration. Accepts the same values as the filter option. The query method will request the remote service if the serverFiltering option is set to true.

options.group Object|Array (optional)

The grouping configuration. Accepts the same values as the filter option. The query method will request the remote service if the serverGrouping option is set to true.

options.page Number (optional)

The page of data to return. The query method will request the remote service if the serverPaging option is set to true.

options.pageSize Number (optional)

The number of data items to return. The query method will request the remote service if the serverPaging option is set to true.

options.sort Object|Array (optional)

The sort configuration. Accepts the same values as the sort option. The query method will request the remote service if the serverSorting option is set to true.

Returns

Promise—A promise that will be resolved when the data has been loaded or rejected if an HTTP error occurs.

Example - query the data source

<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      url: "https://demos.telerik.com/kendo-ui/service/products",
      dataType: "jsonp" // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
    }
  },
  change: function(e) {
    var view = this.view();
    /* The result can be observed in the DevTools(F12) console of the browser. */
    console.log(view)
    console.log(view[0].ProductName); // displays "Manjimup Dried Apples"
  }
});
// Filter only results with ProductID greather than 30, sort by "ProductName" and get the second page with page size set to 20. 
dataSource.query({
  sort: { field: "ProductName", dir: "desc" },
  filter: { field: "ProductID", operator: "gt", value: 30 },
  page: 2,
  pageSize: 20
});
</script>

Example - use the Promise API to get notified when the query finishes

<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      url: "https://demos.telerik.com/kendo-ui/service/products",
      dataType: "jsonp"
    }
  }
});

// sort by "ProductName" and get the third page with page size set to 20
dataSource.query({
  sort: { field: "ProductName", dir: "desc" },
  page: 3,
  pageSize: 20
}).then(function(e) {
    var view = dataSource.view();
/* The result can be observed in the DevTools(F12) console of the browser. */
    console.log(view[0].ProductName); // displays "Manjimup Dried Apples"
  });
</script>
In this article