jQuery UI Widgets Forums Grid Reading XML attribute while creating source for a jqxGrid

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 8 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • samratsaha2
    Participant

    How can I read an attribute of a XML during creating source for a jqxGrid.

    Please consider below example

    var source =
    {
    datatype: “xml”,
    datafields: datafields,
    root: “STOPS”,
    record: “STOP”,
    localdata: requestString
    };

    and xml is as below

    <STOPS><STOP DRVR_CONFIRMED_STOP_LOCS_REQD=”TRUE”><NAME>SAMRAT COMMUNICATIONS</NAME><GEOCODE_MATCH>M</GEOCODE_MATCH><HOUSE>7664</HOUSE><STREET>OLD AUBURN RD BLD B</STREET><CITY>CITRUS HEIGHTS</CITY><STATE>CA</STATE><ZIP_CD>95610-3831</ZIP_CD></STOP><STOP DRVR_CONFIRMED_STOP_LOCS_REQD=”FALSE”><NAME>SAMRAT COMMUNICATIONS 2</NAME><GEOCODE_MATCH>U</GEOCODE_MATCH><HOUSE>7664</HOUSE><STREET>OLD FARM</STREET><CITY>CITRUS HEIGHTS</CITY><STATE>CA</STATE><ZIP_CD>95610-3831</ZIP_CD></STOP></STOPS></REQUEST>

    I need to read DRVR_CONFIRMED_STOP_LOCS_REQD attribute of each STOP element and need to display as column.


    Dimitar
    Participant

    Hello samratsaha2,

    Here is an example from the guide Grid Data Sources:

    Example #2 with XML Attributes Let’s load the following data into the Grid from a file named customers.xml.

    <?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>

    Initialize the jqxDataAdapter plug-in.

    var url = "../sampledata/customers.xml";
    // prepare the data
    var source =
    {
        datatype: "xml",
        datafields: [
            { name: 'CustomerID', map: '[CustomerID]' },
            { name: 'Name', map: '[Name]' }
        ],
        root: "Customers",
        record: "Customer",
        url: url
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    Initialize the jqxGrid.

                $("#jqxgrid").jqxGrid(
                {
                    width: 400,
                    source: dataAdapter,
                    columns: [
                      { text: 'ID', datafield: 'CustomerID', width: 250 },
                      { text: 'Name', datafield: 'Name', width: 150 }
                    ]
                });

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.