var source =
{
datatype: "xml",
datafields: [
{ name: 'ShippedDate', map: 'm\\:properties>d\\:ShippedDate', type: 'date' },
{ name: 'Freight', map: 'm\\:properties>d\\:Freight', type: 'float' },
{ name: 'ShipName', map: 'm\\:properties>d\\:ShipName' },
{ name: 'ShipAddress', map: 'm\\:properties>d\\:ShipAddress' },
{ name: 'ShipCity', map: 'm\\:properties>d\\:ShipCity' },
{ name: 'ShipCountry', map: 'm\\:properties>d\\:ShipCountry' }
],
root: "entry",
record: "content",
id: 'm\\:properties>d\\:OrderID',
url: 'orders.xml'
};
<entry> <id>http://services.odata.org/Northwind/Northwind.svc/Orders(10248)</id> <title type="text"></title> <updated>2011-12-01T11:55:06Z</updated> <author> <name /> </author> <link rel="edit" title="Order" href="Orders(10248)" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer" type="application/atom+xml;type=entry" title="Customer" href="Orders(10248)/Customer" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Employee" type="application/atom+xml;type=entry" title="Employee" href="Orders(10248)/Employee" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Orders(10248)/Order_Details" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Shipper" type="application/atom+xml;type=entry" title="Shipper" href="Orders(10248)/Shipper" /> <category term="NorthwindModel.Order" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:OrderID m:type="Edm.Int32">10248</d:OrderID> <d:CustomerID>VINET</d:CustomerID> <d:EmployeeID m:type="Edm.Int32">5</d:EmployeeID> <d:OrderDate m:type="Edm.DateTime">1996-07-04T00:00:00</d:OrderDate> <d:RequiredDate m:type="Edm.DateTime">1996-08-01T00:00:00</d:RequiredDate> <d:ShippedDate m:type="Edm.DateTime">1996-07-16T00:00:00</d:ShippedDate> <d:ShipVia m:type="Edm.Int32">3</d:ShipVia> <d:Freight m:type="Edm.Decimal">32.3800</d:Freight> <d:ShipName>Vins et alcools Chevalier</d:ShipName> <d:ShipAddress>59 rue de l'Abbaye</d:ShipAddress> <d:ShipCity>Reims</d:ShipCity> <d:ShipRegion m:null="true" /> <d:ShipPostalCode>51100</d:ShipPostalCode> <d:ShipCountry>France</d:ShipCountry> </m:properties> </content> </entry> <entry> <id>http://services.odata.org/Northwind/Northwind.svc/Orders(10249)</id> <title type="text"></title> <updated>2011-12-01T11:55:06Z</updated> <author> <name /> </author> <link rel="edit" title="Order" href="Orders(10249)" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer" type="application/atom+xml;type=entry" title="Customer" href="Orders(10249)/Customer" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Employee" type="application/atom+xml;type=entry" title="Employee" href="Orders(10249)/Employee" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Orders(10249)/Order_Details" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Shipper" type="application/atom+xml;type=entry" title="Shipper" href="Orders(10249)/Shipper" /> <category term="NorthwindModel.Order" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <content type="application/xml"> <m:properties> <d:OrderID m:type="Edm.Int32">10249</d:OrderID> <d:CustomerID>TOMSP</d:CustomerID> <d:EmployeeID m:type="Edm.Int32">6</d:EmployeeID> <d:OrderDate m:type="Edm.DateTime">1996-07-05T00:00:00</d:OrderDate> <d:RequiredDate m:type="Edm.DateTime">1996-08-16T00:00:00</d:RequiredDate> <d:ShippedDate m:type="Edm.DateTime">1996-07-10T00:00:00</d:ShippedDate> <d:ShipVia m:type="Edm.Int32">1</d:ShipVia> <d:Freight m:type="Edm.Decimal">11.6100</d:Freight> <d:ShipName>Toms Spezialitäten</d:ShipName> <d:ShipAddress>Luisenstr. 48</d:ShipAddress> <d:ShipCity>Münster</d:ShipCity> <d:ShipRegion m:null="true" /> <d:ShipPostalCode>44087</d:ShipPostalCode> <d:ShipCountry>Germany</d:ShipCountry> </m:properties> </content> </entry>
{ name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName' }
<content type="application/xml"> <m:properties> <d:CustomerID>ALFKI</d:CustomerID> <d:CompanyName>Alfreds Futterkiste</d:CompanyName> <d:ContactName>Maria Anders</d:ContactName> <d:ContactTitle>Sales Representative</d:ContactTitle> <d:Address>Obere Str. 57</d:Address> <d:City>Berlin</d:City> <d:Region m:null="true" /> <d:PostalCode>12209</d:PostalCode> <d:Country>Germany</d:Country> <d:Phone>030-0074321</d:Phone> <d:Fax>030-0076545</d:Fax> </m:properties> </content>
var data = [{ "empName": "test", "age": "67", "department": { "id": "1234", "name": "Sales" }, "author": "ravi"}];
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'empName' },
{ name: 'age' },
{ name: 'id', map: 'department>id' },
{ name: 'name', map: 'department>name' },
{ name: 'author' }
],
localdata: data
};
var dataAdapter = new $.jqx.dataAdapter(source);
<?xml version="1.0" encoding="utf-8" standalone="yes"?><Customers><Customer CustomerID="1" Name="Customer 1"></Customer><Customer CustomerID="2" Name="Customer 2"></Customer></Customers>
var url = "../sampledata/customers.xml";// prepare the datavar source ={ datatype: "xml", datafields: [ { name: 'CustomerID', map: '[CustomerID]' }, { name: 'Name', map: '[Name]' } ], root: "Customers", record: "Customer", url: url};var dataAdapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid( { width: 400, source: dataAdapter, columns: [ { text: 'ID', datafield: 'CustomerID', width: 250 }, { text: 'Name', datafield: 'Name', width: 150 } ] });
var data = [
{
"state": {
"id": "x526",
"city": {
"name": "Beverly Hills",
"id": 90210,
"value": "Beverly Hills"
}
}
}
];
var source = {
datatype: 'json',
localdata: data,
datafields:
[
{
name: 'cityName', map: 'state>city>name'
}
]
};
var dataAdapter = new $.jqx.dataAdapter(source);
var employeesSource =
{
datatype: "xml",
datafields: [
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' }
],
root: "Employees",
record: "Employee",
id: 'EmployeeID',
url: "../sampledata/employees.xml",
async: false
};
var employeesAdapter = new $.jqx.dataAdapter(employeesSource, {
autoBind: true,
beforeLoadComplete: function (records) {
var data = new Array();
// update the loaded records. Dynamically add EmployeeName and EmployeeID fields.
for (var i = 0; i < records.length; i++) {
var employee = records[i];
employee.EmployeeName = employee.FirstName + " " + employee.LastName;
employee.EmployeeID = employee.uid;
data.push(employee);
}
return data;
}
});
// prepare the data
var ordersSource =
{
datatype: "xml",
datafields: [
// name - determines the field's name.
// value - the field's value in the data source.
// values - specifies the field's values.
// values.source - specifies the foreign source. The expected value is an array.
// values.value - specifies the field's name in the foreign source.
// values.name - specifies the field's value in the foreign source.
// When the ordersAdapter is loaded, each record will have a field called "EmployeeName". The "EmployeeName" for each record comes from the employeesAdapter where the record's "EmployeeID" from orders.xml matches to the "EmployeeID" from employees.xml.
{ name: 'EmployeeName', value: 'EmployeeID', values: { source: employeesAdapter.records, value: 'EmployeeID', name: 'EmployeeName' } },
{ name: 'EmployeeID', map: 'm\\:properties>d\\:EmployeeID' },
{ name: 'ShippedDate', map: 'm\\:properties>d\\:ShippedDate', type: 'date' },
{ name: 'Freight', map: 'm\\:properties>d\\:Freight', type: 'float' },
{ name: 'ShipName', map: 'm\\:properties>d\\:ShipName' },
{ name: 'ShipAddress', map: 'm\\:properties>d\\:ShipAddress' },
{ name: 'ShipCity', map: 'm\\:properties>d\\:ShipCity' },
{ name: 'ShipCountry', map: 'm\\:properties>d\\:ShipCountry' }
],
root: "entry",
record: "content",
id: 'm\\:properties>d\\:OrderID',
url: "../sampledata/orders.xml",
pager: function (pagenum, pagesize, oldpagenum) {
// callback called when a page or page size is changed.
}
};
var ordersAdapter = new $.jqx.dataAdapter(ordersSource);
pager: function (pagenum, pagesize, oldpagenum) {
}
sort: function (column, direction) {
}
filter: function (filters, recordsArray)
{
}
addrow: function (rowid, rowdata, position, commit) {
// synchronize with the server - send insert command
// call commit with parameter true if the synchronization with the server is successful
//and with parameter false if the synchronization failed.
commit(true);
}
deleterow: function (rowid, commit) {
// synchronize with the server - send delete command
// call commit with parameter true if the synchronization with the server is successful
//and with parameter false if the synchronization failed.
commit(true);
}
updaterow: function (rowid, newdata, commit) {
// synchronize with the server - send update command
// call commit with parameter true if the synchronization with the server is successful
// and with parameter false if the synchronization failed.
commit(true);
}
var source ={ datatype: "jsonp", datafields: [ { name: 'countryName' }, { name: 'name' }, { name: 'population', type: 'float' }, { name: 'continentCode' } ], url: "http://ws.geonames.org/searchJSON", processdata: function (data) { data.featureClass = "P";; data.style = "full"; data.maxRows = 50; }};
var source ={ datatype: "jsonp", datafields: [ { name: 'countryName' }, { name: 'name' }, { name: 'population', type: 'float' }, { name: 'continentCode' } ], url: "http://ws.geonames.org/searchJSON", data: { featureClass: "P", style: "full", maxRows: 50 }, formatdata: function (data) { return "my data"; }};
var dataAdapter = new $.jqx.dataAdapter(source, { loadComplete: function (data) { // data is loaded. }, loadError: function (xhr, status, error) { // data is not loaded. } });
var url = "../sampledata/beverages.txt";
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'name' },
{ name: 'type' },
{ name: 'calories', type: 'int' },
{ name: 'totalfat' },
{ name: 'protein' }
],
id: 'id',
url: url
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid(
{
width: 400,
source: dataAdapter,
ready: function () {
$("#jqxgrid").jqxGrid('hidecolumn', 'name');
},
columnsresize: true,
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', minwidth: 120 }
]
});
Example with 'bindingcomplete':
var url = "../sampledata/beverages.txt";
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'name' },
{ name: 'type' },
{ name: 'calories', type: 'int' },
{ name: 'totalfat' },
{ name: 'protein' }
],
id: 'id',
url: url
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").bind('bindingcomplete', function (event) {
$("#jqxgrid").jqxGrid('hidecolumn', 'name');
});
$("#jqxgrid").jqxGrid(
{
width: 400,
source: dataAdapter,
columnsresize: true,
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', minwidth: 120 }
]
});
Initialize a Grid with the source property specified.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://services.odata.org/Northwind/Northwind.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Customers</title>
<updated>2012-11-30T11:39:28Z</updated>
<link rel="self" title="Customers" href="Customers" />
<entry>
<title type="text"></title>
<updated>2012-11-30T11:39:28Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:CustomerID>ALFKI</d:CustomerID>
<d:CompanyName>Alfreds Futterkiste</d:CompanyName>
<d:ContactName>Maria Anders</d:ContactName>
<d:ContactTitle>Sales Representative</d:ContactTitle>
<d:Address>Obere Str. 57</d:Address>
<d:City>Berlin</d:City>
<d:Region m:null="true" />
<d:PostalCode>12209</d:PostalCode>
<d:Country>Germany</d:Country>
<d:Phone>030-0074321</d:Phone>
<d:Fax>030-0076545</d:Fax>
</m:properties>
</content>
</entry>
</feed>
var data = [{ "empName": "test", "age": "67", "department": { "id": "1234", "name": "Sales" }, "author": "ravi"}];
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'empName' },
{ name: 'age' },
{ name: 'id', map: 'department>id' },
{ name: 'name', map: 'department>name' },
{ name: 'author' }
],
localdata: data
};
var dataAdapter = new $.jqx.dataAdapter(source);