jQWidgets Forums

jQuery UI Widgets Forums Grid Binding DataTable to XML Attribute

This topic contains 5 replies, has 2 voices, and was last updated by  Dimitar 10 years, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • Binding DataTable to XML Attribute #61237

    harsh
    Participant

    Hi,

    I want to bind data table to a much below similar Array of XML(string) document and use attribute value instead of using element value. For example, my XML document has the following format:

    var xmlData = [‘<r:table_name>
    <r:Record r:id=”1″ r:firstname=”Joe1″ r:lastname = “Smith1″ r:telephone=”1234567890″ />
    </r:table_name>’,
    ‘<r:table_name>
    <r:Record id=”1″ r:firstname=”Joe2″ r:lastname = “Smith2″ r:telephone=”1234567890″ />
    </r:table_name>’
    ]

    I tried to pass data as a localdata and map the fields using the following xpaths, but it does not work:

    var source =
    {
    localdata: xmlData,
    datatype: “xml”,
    datafields: [
    { name: ‘firstname’, map: ‘[r\\:firstname]‘, type: ‘string’ },
    { name: ‘lastname’, map: ‘[r\\:lastname]‘, type: ‘string’ },
    { name: ‘telephone’, map: ‘[r\\:telephone]‘, type: ‘string’ }
    ],

    How do I format the source with localdata\datafields etc…?

    Thanks in advance!
    Harsh

    Binding DataTable to XML Attribute #61278

    Dimitar
    Participant

    Hello Harsh,

    Your local XML data has to be stored as a string, not an array. Please refer to the following example, which shows how to bind a jqxDataTable to XML attributes: http://www.jqwidgets.com/community/topic/binding-datatable-to-xml-attribute/#post-48916.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Binding DataTable to XML Attribute #61281

    harsh
    Participant

    It’s working fine when xml doesn’t have namespace. But how to use with namespace?

    Thanks,
    Harsh

    Binding DataTable to XML Attribute #61295

    Dimitar
    Participant

    Hi Harsh,

    jqxGrid can be bound to an XML with namespaces, as shown in the demo Binding to XML.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Binding DataTable to XML Attribute #61305

    harsh
    Participant

    Thanks, Do you have any example which are showing data using XML attribute with namespaces?

    Thanks,
    Harsh

    Binding DataTable to XML Attribute #61370

    Dimitar
    Participant

    Hi Harsh,

    Here is an example with your data source:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.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" src="../../scripts/demos.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var url = "../sampledata/customers.xml";
    
                var xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><feed xml:base="http://services.odata.org/Northwind/Northwind.svc/" xmlns:r="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns="http://www.w3.org/2005/Atom"><r:table_name><r:Record id="5" r:firstname="Joe1" r:lastname = "Smith1" r:telephone="1234567890" /><r:Record id="1" r:firstname="Joe2" r:lastname = "Smith2" r:telephone="1234567890" /></r:table_name></feed>';
    
                // prepare the data
                var source =
                {
                    datatype: "xml",
                    datafields: [
                        { name: 'firstname', map: '[r:firstname]', type: 'string' },
                        { name: 'lastname', map: '[r:lastname]', type: 'string' },
                        { name: 'telephone', map: '[r:telephone]', type: 'string' }
                     ],
                    root: "r\\:table_name",
                    record: "r\\:Record",
                    localdata: xml
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                // Create jqxGrid
                $("#jqxgrid").jqxGrid(
                {
                    width: 850,
                    autoheight: true,
                    source: dataAdapter,
                    columnsresize: true,
                    columns: [
                      { text: 'Company Name', datafield: 'firstname' },
                      { text: 'Contact Name', datafield: 'lastname' },
                      { text: 'Contact Title', datafield: 'telephone' }
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;">
            <div id="jqxgrid">
            </div>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.