Data Layer DataSource

An object that provides access to a data web service or local data storage for collection container widgets.

Type: Object

A DataSource object is the connection between a collection container widget and the data provided by a web service or data stored locally. The data source object is created within a collection container widget when you pass an array or a data source configuration object to the widget's dataSource option.

If the widget works with data stored locally in an array, pass this array to the widget's dataSource option.

JavaScript
var viewModel = {
    myData: [
        { id:1, name: "Bob", hired: 2005 },
        { id:2, name: "John", hired: 2007 },
        { id:3, name: "Frank", hired: 2001 },
        { id:4, name: "Robert", hired: 2007 },
        { id:5, name: "Paul", hired: 2011 }
    ]
}
ko.applyBindings(viewModel);
HTML
<div data-bind="dxList: { dataSource: myData }"></div>

If the widget loads the data dynamically page by page, or if it uses a remote data store, implement the required data source configuration object and pass it to the dataSource option of the widget.

JavaScript
var viewModel = {
    dataSourceOptions: {
        load: function (loadOptions) {
            // load implementation
        },
    }
}
ko.applyBindings(viewModel);
HTML
<div data-bind="dxList: { dataSource: dataSourceOptions }"></div>

If you need to load data from a remote server, implement the function that includes the required functionality and pass it to the load field of the data source configuration object.

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 topic for more information about the DataSource object.

Configuration

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