jQuery UI Widgets › Forums › DataTable › Xml file with attribute and elements
Tagged: data, data adapter, data table, dataadapter, datatable, jqxDataAdapter, jqxdatatable, map, mapping, record, XML
This topic contains 1 reply, has 2 voices, and was last updated by Dimitar 9 years, 7 months ago.
-
Author
-
Hi,
I want jqxDataTable to show data from a xml file. With a simple xml file everything works well but mine is a little more complex.My xml file is:
<St> <Building id="A"> <properties> <Company>Alfreds Futterkiste</Company> <ContactName>Maria Anders</ContactName> <ContactTitle>Sales Representative</ContactTitle> <Company>Ana Trujillo Emparedados y helados</Company> <ContactName>Ana Trujillo</ContactName> <ContactTitle>Owner</ContactTitle> </properties> </Building> <Building id="B"> <properties> <Company>Antonio Moreno Taquería</Company> <ContactName>Antonio Moreno</ContactName> <ContactTitle>Owner</ContactTitle> <Company>Around the Horn</Company> <ContactName>Thomas Hardy</ContactName> <ContactTitle>Sales Representative</ContactTitle> </properties> </Building> <Building id="C"> <properties> <Company>Berglunds snabbköp</Company> <ContactName>Christina Berglund</ContactName> <ContactTitle>Order Administrator</ContactTitle> </properties> </Building> </St>
I have the following code for the datatable:
$(document).ready(function () { var url = "customers.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'id', map: '[id]', type: 'string' }, { name: 'ContactName', map: 'properties>ContactName', type: 'string' }, { name: 'ContactTitle', map: 'properties>ContactTitle', type: 'string' } ], root: "St", record: "Building", url: url }; var dataAdapter = new $.jqx.dataAdapter(source); // Create jqxGrid $("#dataTable").jqxDataTable( { width: 850, source: dataAdapter, pageable: true, pagerButtonsCount: 10, columnsResize: true, columns: [ { text: 'Company Name', datafield: 'id', width: 250 }, { text: 'Contact Name', datafield: 'ContactName', width: 250 }, { text: 'Contact Title', datafield: 'ContactTitle', width: 250 } ] }); });
The problem is that it only show 3 records (Alfreds, Antonio & Berglunds) So it means it can’t read the 2nd record under the same building attribute. How can I make it show it without changing my xml file?
Thanks
Hi tranen,
Unfortunately, without changing your XML, you would not be able to load all contacts. Each Building tag encompasses a single record, as far as the data adapter is concerned, because of the setting
record: "Building"
.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.