JavaScript/jQuery Sankey - Custom Sources

To bind DevExtreme Sankey to a custom data source, implement a CustomStore. You can use the following extensions to configure CustomStore and implement server-side data processing to bind DevExtreme components to Web API and MongoDB services:

To access a server that uses another technology, configure the CustomStore manually. In this case, data 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 following example:

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

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, and others) you enabled in the DataSource. The following settings apply to the Sankey:

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

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

The following example shows how to make a query for data:

index.js
  • $(function() {
  • $("#sankeyContainer").dxSankey({
  • dataSource: new DevExpress.data.DataSource({
  • store: new DevExpress.data.CustomStore({
  • load: function(loadOptions) {
  • const d = $.Deferred(),
  • params = {};
  • [
  • "sort",
  • "filter",
  • "searchExpr",
  • "searchOperation",
  • "searchValue"
  • ].forEach(function(i) {
  • if(i in loadOptions && isNotEmpty(loadOptions[i]))
  • params[i] = JSON.stringify(loadOptions[i]);
  • });
  • $.getJSON("https://mydomain.com/MyDataService", params)
  • .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();
  • }
  • }),
  • paginate: false
  • })
  • });
  • });
  • function isNotEmpty(value) {
  • return value !== undefined && value !== null && value !== "";
  • }
See Also