Configuration

This section describes configuration options used to configure the data source.

dispose

Specifies a function that releases all resources associated with the data source.

Type: function

The function passed to this option does not have any parameters and returns nothing.

isLoaded

Specifies a function that indicates whether or not the data source is loading data.

Type: function

The function passed to this option should return 'true' if data is being loaded; otherwise, it should return 'false'.

load

Specifies a function that loads data to the data source and refreshes the associated widgets.

Type: function

The function passed to this option should get an object specifying loading options as a parameter, and return a value containing the requested data. The parameter object may include the following fields.

  • refresh - specifies whether or not widget data should be refreshed completely.
  • searchString - this field is passed to the data source by the dxAutocomplete or dxLookup widgets; this field specifies the search pattern used to filter the returned array.

The function can return the following results.

  • A Deferred object - data can be loaded asynchronously and provided for a control via the resolve function.
  • An array of objects.
  • Nothing - indicates that no data is available when auto paging is enabled.

The following code demonstrates how to get Category objects from the data service, and return them via the dataSource's load function.

JavaScript
var viewModel = {
    dataSourceOptions: {
        load: function (loadOptions) {
            var dfd = new $.Deferred();
            if (loadOptions.refresh) {
                $.get('http://sampleservices.devexpress.com/api/Categories')
                    .done(function (result) {
                        dfd.resolve(result);
                    });
                return dfd.promise();
            }
        }
    }
}

Refer to the Data-Bound Application tutorial for more information on the DataSource load method.

lookup

Specifies a function that loads the data item specified by a key.

Type: function

If you use the DataSource with the dxLookup widget, also implement the lookup(lookupOptions) method. The lookupOptions object contains the key field, which specifies the key value for the required DataSource item. The method should return the object whose key value matches the specified value, or the promise() method of the JQuery Deferred object whose resolve field contains this object.

JavaScript
var viewModel = {
    dataSourceOptions: {
        lookup: function (loadOptions) {
            var dfd = new $.Deferred();
            if (loadOptions.refresh) {
                $.get('http://sampleservices.devexpress.com/api/Categories')
                    .done(function (result) {
                        dfd.resolve(result);
                    });
                return dfd.promise();
            }
        }
    }
}

nextPage

Specifies a function that loads data for the next page from the data source.

Type: function

The function passed to this option should have the append Boolean input parameter. If the parameter is set to 'true', the function should return both the previously loaded data and the new page data. Otherwise, it should only return the new page data.

The function may return the data array, or the promise of the jQuery Deferred object containing the data array.