DevExtreme jQuery/JS - Custom Sources

DevExtreme provides the CustomStore component, a flexible instrument that allows you to configure data access manually, for consuming data from any source. The following extensions for ASP.NET and PHP servers simplify the task of configuring the CustomStore and implement server-side data processing as well:

You need to configure the CustomStore in detail for accessing a server built on another technology. Data in this situation can be processed on the client or server. In the former case, switch the CustomStore to the raw mode and load all data from the server in the load function as shown in the next example.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • dataSource: new DevExpress.data.DataSource({
  • store: new DevExpress.data.CustomStore({
  • loadMode: "raw",
  • load: function () {
  • return $.getJSON('https://mydomain.com/MyDataService');
  • }
  • }),
  • paginate: false
  • })
  • });
  • });

View Demo

In the latter case, use the CustomStore's load function to send data processing settings to the server. These settings are passed as a parameter to the load function and depend on the operations (filtering, sorting, etc.) that you have enabled in the DataSource. The following settings are relevant for the Chart:

  • sort: Array
    Defines sorting parameters. Present if the DataSource's sort option is set. Multiple parameters apply to the data in sequence to implement multi-level sorting. Contains objects of the following structure:

    • { selector: "field", desc: true/false }
  • filter: Array
    Defines filtering parameters. Present if the DataSource's filter option is set. Possible variants:

    • Binary filter

      • [ "field", "=", 3 ]
    • Unary filter

      • [ "!", [ "field", "=", 3 ] ]
    • Complex filter

      • [
      • [ "field", "=", 10 ],
      • "and",
      • [
      • [ "otherField", "<", 3 ],
      • "or",
      • [ "otherField", ">", 11 ]
      • ]
      • ]

    See the Filtering topic for more details.

  • searchExpr, searchOperation and searchValue: Strings
    Another way to define a filter restricted to one criterion. Present if corresponding options are set in the DataSource.

After receiving these settings, the server should apply them to data and send back an object of the following structure:

  • {
  • data: [ ... ] // result data objects
  • }

This example shows how to make a query for data.

JavaScript
  • $(function() {
  • $("#chartContainer").dxChart({
  • dataSource: new DevExpress.data.DataSource({
  • load: function (loadOptions) {
  • var d = $.Deferred();
  • $.getJSON("http://mydomain.com/MyDataService", {
  • sort: loadOptions.sort ? JSON.stringify(loadOptions.sort) : "",
  • filter: loadOptions.filter ? JSON.stringify(loadOptions.filter) : "",
  • searchExpr: loadOptions.searchExpr ? JSON.stringify(loadOptions.searchExpr) : "",
  • searchOperation: loadOptions.searchOperation,
  • searchValue: loadOptions.searchValue
  • }).done(function(result) {
  • // Here, you can perform operations unsupported by the server
  • // or any other operations on the retrieved data
  • d.resolve(result.data);
  • });
  • return d.promise();
  • }
  • })
  • });
  • });
See Also