DataTable Data Sources

The DataTable plugin can be bound to multiple types of data collections including arrays, xml, json, tsv, csv or remote data. To data bind the DataTable to a data source you need to set its source property to point to an instance of jqxDataAdapter.

The source object represents a set of key/value pairs.
The example code below illustrates how to create jqxDataAdapter from a source object.
var dataAdapter = new $.jqx.dataAdapter(source, {
loadComplete: function (data)
{
// data is loaded.
},
loadError: function (xhr, status, error)
{
// data is not loaded.
}
});

If you bind the DataTable to a remote data source using asynchronous requests(that is by default when you set the source object's url member and you did not set the async field to false), then make sure that you call any method or set a property once the data is loaded. To ensure that you call your code when the DataTable is loaded with data, you can use the DataTable's ready callback function or bind to the bindingComplete event before the DataTable's initialization and add your code inside the event handler.

Example

The sample code below shows how to use the ready callback function:

var url = "../sampledata/beverages.txt";
// prepare the data
var source =
{
 dataType: "json",
 dataFields: [
 { name: 'name', type: 'string' },
 { name: 'type', type: 'string' },
 { name: 'calories', type: 'int' },
 { name: 'totalfat', type: 'string' },
 { name: 'protein', type: 'string' }
 ],
 id: 'id',
 url: url
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#dataTable").jqxDataTable(
{
 width: 400,
 source: dataAdapter,
 ready: function () {
 $("#dataTable").jqxDataTable('hideColumn', 'name');
 },
 columns: [
 { text: 'Name', dataField: 'name', width: 250 },
 { text: 'Beverage Type', dataField: 'type', width: 250 },
 { text: 'Calories', dataField: 'calories', width: 180 },
 { text: 'Total Fat', dataField: 'totalfat', width: 120 },
 { text: 'Protein', dataField: 'protein', width: 100}
 ]
}); 

Example

The sample code below shows how to use the bindingComplete event:

var url = "../sampledata/beverages.txt";
// prepare the data
var source =
{
 dataType: "json",
 dataFields: [
 { name: 'name', type: 'string' },
 { name: 'type', type: 'string' },
 { name: 'calories', type: 'int' },
 { name: 'totalfat', type: 'string' },
 { name: 'protein', type: 'string' }
 ],
 id: 'id',
 url: url
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#dataTable").on('bindingComplete', function(event)
{
 $("#dataTable").jqxDataTable('hideColumn', 'name');
});
$("#dataTable").jqxDataTable(
{
 width: 400,
 source: dataAdapter,
 columns: [
 { text: 'Name', dataField: 'name', width: 250 },
 { text: 'Beverage Type', dataField: 'type', width: 250 },
 { text: 'Calories', dataField: 'calories', width: 180 },
 { text: 'Total Fat', dataField: 'totalfat', width: 120 },
 { text: 'Protein', dataField: 'protein', width: 100}
 ]
}); 

AltStyle によって変換されたページ (->オリジナル) /