jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Load XML data from a non-root element
Tagged: datagrid xml binding, jqxgrid
This topic contains 11 replies, has 2 voices, and was last updated by jerry@zmjjohnson.com 12 years, 3 months ago.
-
Author
-
All of the samples appear to use the attributes root and record to load XML data into the grid. But I can’t find any examples where the root element is not reading from the root element of the file. I have an XML file such as this:
<root><level1><level2><record/><record/></level2></level2></root>
And I need to read the “records” whose parent is level2. I’ve tried setting the root attribute to level2 and I’ve tried root/level1/level2 but neither seems to read the data from the xml file.
What is the syntax needed to indicate a root for the data source that is not the first element in the file?
Hi jerry,
Please send us a sample of such XML file including sample Data and we will try to help you loading it.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHere is my source:
MTMMeetingDate
DateTime
MTM Meeting Date
Compass Smart FormsMTMMeetingNbr
Text
MTM Meeting Nbr
Compass Smart FormsMTMMeetingType
Text
MTM Meeting Type
Compass Smart FormsCompassContent
DocumentLibraryCodeFile
Custom ListCodeType
TextSortOrder
IntegerAll Items
CodeType
TrueCodeType
SortOrder
LinkTitle
CodeType
Docuemnt TypeSortOrder
1Title
SubmittalCodeType
Docuemnt TypeSortOrder
2Title
DrawingsAdministrative
DocumentLibraryAnnouncements
AnnouncementsBid Documents
DocumentLibraryEntity
Lookup
Company
TitleBid Doc Type
ChoiceDrawing
InformationDoc Description
TextNotes
NoteMeetingMinutes
Form Library
MeetingMinutesAll Documents
ID
FalseDocIcon
LinkFilename
Modified
Editor
CheckoutUser
MTMPrepBy
MTMMeetingDate
MTMSubject
MTMMeetingNbr
MTMMeetingType
and here is the code:
var source =
{
datafields: [
{ name: ‘SiteColumnName’ },
{ name: ‘SiteColumnType’ },
{ name: ‘SiteColumnDisplay’ },
{ name: ‘SiteColumnGroup’ }
],
root: “RootSiteColumns”,
record: “SiteColumn”,
id: ‘ID’,
datatype: “xml”,
async: false,
url: url
};I need to bind the grid to the SiteColumn elements.
Thank you for your assistance.
I’m not sure my copy/paste of the XML looks correct. Here’s another snippet:
‘
‘
‘
‘
‘
‘ MTMMeetingDate
‘ DateTime
‘ MTM Meeting Date
‘ Compass Smart Forms
‘
‘
‘ MTMMeetingNbr
‘ Text
‘ MTM Meeting Nbr
‘ Compass Smart Forms
‘
‘
‘ MTMMeetingType
‘ Text
‘ MTM Meeting Type
‘ Compass Smart Forms
‘
‘
‘
‘
‘ …I don’t understand how to post my XML to you on this forum. It keeps removing my tags.
The tag structure is as follows:
CompassSetup -> RootSite -> RootSiteColumns
and then there are multiple SiteColumn nodes under the RootSiteColumns node
Hi Jerry,
To post HTML, XML, JavaScript, please take a look at this topic: http://www.jqwidgets.com/community/topic/code-formatting/
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com<CompassSetup> <RootSite> <!--RootSiteURL></RootSiteURL--> <RootSiteColumns> <SiteColumn ID="1"> <SiteColumnName>MTMMeetingDate</SiteColumnName> <SiteColumnType>DateTime</SiteColumnType> <SiteColumnDisplay>MTM Meeting Date</SiteColumnDisplay> <SiteColumnGroup>Compass Smart Forms</SiteColumnGroup> </SiteColumn> <SiteColumn ID="2"> <SiteColumnName>MTMMeetingNbr</SiteColumnName> <SiteColumnType>Text</SiteColumnType> <SiteColumnDisplay>MTM Meeting Nbr</SiteColumnDisplay> <SiteColumnGroup>Compass Smart Forms</SiteColumnGroup> </SiteColumn> <SiteColumn ID="3"> <SiteColumnName>MTMMeetingType</SiteColumnName> <SiteColumnType>Text</SiteColumnType> <SiteColumnDisplay>MTM Meeting Type</SiteColumnDisplay> <SiteColumnGroup>Compass Smart Forms</SiteColumnGroup> </SiteColumn> </RootSiteColumns> <RootLists></RootLists> </RootSite></CompassSetup>can you answer my original question? thank you
Hi Jerry,
Here’s a sample which uses your data:
<!DOCTYPE html><html lang="en"><head> <title id='Description'>This example shows how to create a Grid from XML data.</title> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.9.0.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.js"></script> <script type="text/javascript"> $(document).ready(function () { var url = "data.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'SiteColumnName'}, { name: 'SiteColumnType'}, { name: 'SiteColumnDisplay'}, { name: 'SiteColumnGroup'} ], root: "CompassSetup", record: "SiteColumn", url: url }; var dataAdapter = new $.jqx.dataAdapter(source); // Create jqxGrid $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, columns: [ { text: 'SiteColumnName', datafield: 'SiteColumnName', width: 250 }, { text: 'SiteColumnType', datafield: 'SiteColumnType', width: 150 }, { text: 'SiteColumnDisplay', datafield: 'SiteColumnDisplay', width: 180 }, { text: 'SiteColumnGroup', datafield: 'SiteColumnGroup'} ] }); }); </script></head><body class='default'> <div id="jqxgrid"></div></body></html>
Where data.xml is:
<CompassSetup> <RootSite> <!--RootSiteURL></RootSiteURL--> <RootSiteColumns> <SiteColumn ID="1"> <SiteColumnName>MTMMeetingDate</SiteColumnName> <SiteColumnType>DateTime</SiteColumnType> <SiteColumnDisplay>MTM Meeting Date</SiteColumnDisplay> <SiteColumnGroup>Compass Smart Forms</SiteColumnGroup> </SiteColumn> <SiteColumn ID="2"> <SiteColumnName>MTMMeetingNbr</SiteColumnName> <SiteColumnType>Text</SiteColumnType> <SiteColumnDisplay>MTM Meeting Nbr</SiteColumnDisplay> <SiteColumnGroup>Compass Smart Forms</SiteColumnGroup> </SiteColumn> <SiteColumn ID="3"> <SiteColumnName>MTMMeetingType</SiteColumnName> <SiteColumnType>Text</SiteColumnType> <SiteColumnDisplay>MTM Meeting Type</SiteColumnDisplay> <SiteColumnGroup>Compass Smart Forms</SiteColumnGroup> </SiteColumn> </RootSiteColumns> <RootLists></RootLists> </RootSite></CompassSetup>
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comWow, I must be blind. I feel like I have exactly what you indicated but I get “No data to display”. I’ve copied all the required files into a single folder to simply as much as possible. Can you see what I’m doing wrong? Here is my code:
<!DOCTYPE html><html lang="en"><head> <title id='Description'>Compass setup variables.</title> <link rel="stylesheet" href="jqx.base.css" type="text/css" /> <script type="text/javascript" src="jquery-1.9.0.min.js"></script> <script type="text/javascript" src="jqxcore.js"></script> <script type="text/javascript" src="jqxdata.js"></script> <script type="text/javascript" src="jqxbuttons.js"></script> <script type="text/javascript" src="jqxscrollbar.js"></script> <script type="text/javascript" src="jqxmenu.js"></script> <script type="text/javascript" src="jqxgrid.js"></script> <script type="text/javascript" src="jqxgrid.selection.js"></script> <script type="text/javascript" src="jqxgrid.columnsresize.js"></script> <script type="text/javascript"> $(document).ready(function () { var url = "data.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'SiteColumnName'}, { name: 'SiteColumnType'}, { name: 'SiteColumnDisplay'}, { name: 'SiteColumnGroup'} ], root: "CompassSetup", record: "SiteColumn", url: url }; var dataAdapter = new jQuery.jqx.dataAdapter(source); // Create jqxGrid $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, columns: [ { text: 'SiteColumnName', datafield: 'SiteColumnName', width: 250 }, { text: 'SiteColumnType', datafield: 'SiteColumnType', width: 150 }, { text: 'SiteColumnDisplay', datafield: 'SiteColumnDisplay', width: 180 }, { text: 'SiteColumnGroup', datafield: 'SiteColumnGroup'} ] }); }); </script></head><body class='default'> <div id="jqxgrid"></div></body></html>
Hi Jerry,
As far as I can see, the posted code in your post is the copied code from my post. However, I see the data from data.xml which contains your XML data. If you would like, I can post online example + image of that. My test is with jQWidgets 2.6.1.
Here’s the posted and working code again:
<!DOCTYPE html><html lang="en"><head> <title id='Description'>This example shows how to create a Grid from XML data.</title> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.9.0.min.js"></script> <script type="text/javascript" src="http://jqwidgets.com/public/jqwidgets/jqx-all.js"></script> <script type="text/javascript"> $(document).ready(function () { var url = "data.xml"; // prepare the data var source = { datatype: "xml", datafields: [ { name: 'SiteColumnName'}, { name: 'SiteColumnType'}, { name: 'SiteColumnDisplay'}, { name: 'SiteColumnGroup'} ], root: "CompassSetup", record: "SiteColumn", url: url }; var dataAdapter = new $.jqx.dataAdapter(source); // Create jqxGrid $("#jqxgrid").jqxGrid( { width: 670, source: dataAdapter, columns: [ { text: 'SiteColumnName', datafield: 'SiteColumnName', width: 250 }, { text: 'SiteColumnType', datafield: 'SiteColumnType', width: 150 }, { text: 'SiteColumnDisplay', datafield: 'SiteColumnDisplay', width: 180 }, { text: 'SiteColumnGroup', datafield: 'SiteColumnGroup'} ] }); }); </script></head><body class='default'> <div id="jqxgrid"></div></body></html>
Here’s an image:
In addition, make sure that you run your code on a web server.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comIt was my XML file. I gave you a snippet, but my full file had a typo in it. Well done and thank you for the assist.
-
AuthorPosts
You must be logged in to reply to this topic.