jQuery UI Widgets Forums DataTable DataTable – Problem with reading XML data

This topic contains 13 replies, has 2 voices, and was last updated by  dqninh09@gmail.com 10 years, 9 months ago.

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

  • dqninh09@gmail.com
    Participant

    Hi All,

    I am having an issue with jqxDataTable using XML data. This is my evaluation project. I am testing the ability of jqxDataTable + XML data object, and using the demo code that use the customer.xml data file (as shown below), and instead of having the source read the XML data from the file, I read the file into a XDocument object from the HomeController, put it in the ViewBag.

    `var source =
    {
    datatype: “xml”,
    datafields: [
    { name: ‘mcn_status’, map: ‘m\\:properties>d\\:mcn_status’, type: ‘string’ },
    { name: ‘mcn_serviceidname’, map: ‘m\\:properties>d\\:mcn_serviceidname’, type: ‘string’ },
    { name: ‘mcn_claimant’, map: ‘m\\:properties>d\\:mcn_claimant’, type: ‘string’ },
    { name: ‘mcn_claimnbr’, map: ‘m\\:properties>d\\:mcn_claimnbr’, type: ‘string’ },
    { name: ‘mcn_insurancetype’, map: ‘m\\:properties>d\\:mcn_insurancetype’, type: ‘string’ },
    { name: ‘mcn_product’, map: ‘m\\:properties>d\\:mcn_product’, type: ‘string’ },
    { name: ‘mcn_jurisdiction’, map: ‘m\\:properties>d\\:mcn_jurisdiction’, type: ‘string’ }
    ],
    root: “entry”,
    record: “content”,
    id: ‘m\\:properties>d\\:CustomerID’,
    <strong>localdata: “@(ViewBag.XmlData)”</strong>
    //url: url
    // Use localdata: data if xml data is in a string already
    };`

    With the change fro url to localdata, jqxDataTable gives me the error

    SCRIPT1015: Unterminated string constant

    I exam at the browser debug script, and the localdata looks just fine to me.

    Any comment/suggestion is greatly appreciated.

    Thanks.

    localdata: “<feed xml:base="http://services.odata.org/Northwind/Northwind.svc/&quot; xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices&quot; xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&quot; xmlns="http://www.w3.org/2005/Atom"&gt;
    <title type="text">Customers</title>
    <updated>2011-11-30T11:39:28Z</updated>
    <link rel="self" title="Customers" href="Customers" />
    <entry>
    <title type="text"></title>
    <updated>2011-11-30T11:39:28Z</updated>
    <author>
    <name />
    </author>
    <content type="application/xml">
    <m:properties>
    <d:CustomerID>ALFKI</d:CustomerID>
    <d:mcn_serviceidname>Alfreds Futterkiste</d:mcn_serviceidname>
    <d:mcn_claimant>Maria Anders</d:mcn_claimant>
    <d:mcn_claimnbr>Sales Representative</d:mcn_claimnbr>
    <d:Address>Obere Str. 57</d:Address>
    <d:mcn_insurancetype>Berlin</d:mcn_insurancetype>
    <d:Region m:null="true" />
    <d:mcn_product>12209</d:mcn_product>
    <d:mcn_jurisdiction>Germany</d:mcn_jurisdiction>
    <d:Phone>030-0074321</d:Phone>
    <d:Fax>030-0076545</d:Fax>
    </m:properties>
    </content>
    </entry>
    <entry>

    ……


    Peter Stoev
    Keymaster

    Hi dqninh09,

    I don’t think that the data which you want to display within the DataTable is presented as a correct String. At least it does not look to be a String The code uses “ for building the String, but your data contains “ characters, too. Probably you need to start your String with ‘ instead of ” and also do it on one line. Otherwise, you will have to concatenate strings for all rows.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    dqninh09@gmail.com
    Participant

    Hi Peter,

    Do you have an example code of passing a XML string to the localdata: instead of using the url? All my stored procedure return a XML string (as shown below), and I simply want to set the XML string to localdata:

    <TableName>
    <Record id=”1″ firstname=”Joe1″ lastname=”Smith” telephone=”1234567890″ />
    <Record id=”2″ firstname=”Joe2″ lastname=”Smith” telephone=”1234567890″ />
    <Record id=”3″ firstname=”Joe3″ lastname=”Smith” telephone=”1234567890″ />
    <Record id=”4″ firstname=”Joe4″ lastname=”Smith” telephone=”1234567890″ />
    <Record id=”5″ firstname=”Joe5″ lastname=”Smith” telephone=”1234567890″ />
    </TableName>

    Thanks.


    dqninh09@gmail.com
    Participant

    BTW, the problem is that somehow it does not understand the HTML code for the HTML reserved character and error out at the first “less than” <

    SCRIPT1002: Syntax error

    localdata: <TableName><Record id="1" firstname="Joe1" lastname="Smith" telephone="1234567890" /><Record id="2" firstname="Joe2" lastname="Smith" telephone="1234567890" /><Record id="3" firstname="Joe3" lastname="Smith" telephone="1234567890" /><Record id="4" firstname="Joe4" lastname="Smith" telephone="1234567890" /><Record id="5" firstname="Joe5" lastname="Smith" telephone="1234567890" /></TableName>

    Thanks


    dqninh09@gmail.com
    Participant

    Actually, the above script I copied and pasted it from the browser debug window, which could be confusing. In my code, it is actually much simpler. I am using VS MVC, so my code is written as follow:

    // In the Controller

    ViewBag.XmlData = “<TableName><Record id=\”1\” firstname=\”Joe1\” lastname=\”Smith\” telephone=\”1234567890\” /><Record id=\”2\” firstname=\”Joe2\” lastname=\”Smith\” telephone=\”1234567890\” /><Record id=\”3\” firstname=\”Joe3\” lastname=\”Smith\” telephone=\”1234567890\” /><Record id=\”4\” firstname=\”Joe4\” lastname=\”Smith\” telephone=\”1234567890\” /><Record id=\”5\” firstname=\”Joe5\” lastname=\”Smith\” telephone=\”1234567890\” /></TableName>”;
    return View();

    // And in the index.cshtm file, I simple set the ViewBag.XmlData to the localdata: as shown below

    // prepare the data
    var source =
    {
    datatype: “xml”,
    datafields: [………..],
    root: “TableName”,
    record: “Record”,
    id:”\\id”,
    localdata: @ViewBag.XmlData

    Blablabla….

    I tried to wrap @ViewBag.XmlData with double quotes, single quotes, but still get the error.

    Thanks.


    Peter Stoev
    Keymaster

    Hi dqninh09,

    You need to set the localdata to point to a String.

    localdata: <TableName><Record id="1" firstname="Joe1" lastname="Smith" telephone="1234567890" /><Record id="2" firstname="Joe2" lastname="Smith" telephone="1234567890" /><Record id="3" firstname="Joe3" lastname="Smith" telephone="1234567890" /><Record id="4" firstname="Joe4" lastname="Smith" telephone="1234567890" /><Record id="5" firstname="Joe5" lastname="Smith" telephone="1234567890" /></TableName>
    

    is not String.

    Best Regards,
    Peter Stoev

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


    dqninh09@gmail.com
    Participant

    Hi Peter,

    Do you have sample code that set the “localdata:” to a xml string?

    Thanks.


    Peter Stoev
    Keymaster

    Hi dqninh09,

    We do not have such example.

    Best Regards,
    Peter Stoev

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


    dqninh09@gmail.com
    Participant

    Hi Peter,

    So, would you confirm that there is absolutely no way to use XML data (and so JSON) with jqDataAdapter, unless the XML is written to a file first? Basically, the XML string (or JSON string) requires special handling in a HTML page. All HTML reserved characters must be converted to pre-defined string. For example, double quote must be convert to ", less than sign (<) must be converted to <, and so on… And I don’t see jqDataTable, jqGrid, jqTreeGrid, jqDataAdapter together support the conversion.

    Thanks


    Peter Stoev
    Keymaster

    Hi dqninh09,

    I never wrote that it is not possible and I am very surprised by your post. I wrote that we do not have such sample. Sorry, we do not have samples for every possible scenario. However, we prepared one for you.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title id='Description'>This example shows how to create a Grid from XML string.
        </title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.10.2.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 customersData = '<?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>2011-11-30T11:39:28Z</updated> <link rel="self" title="Customers" href="Customers" /> <entry> <title type="text"></title> <updated>2011-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> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>ANATR</d:CustomerID> <d:CompanyName>Ana Trujillo Emparedados y helados</d:CompanyName> <d:ContactName>Ana Trujillo</d:ContactName> <d:ContactTitle>Owner</d:ContactTitle> <d:Address>Avda. de la Constitución 2222</d:Address> <d:City>México D.F.</d:City> <d:Region m:null="true" /> <d:PostalCode>05021</d:PostalCode> <d:Country>Mexico</d:Country> <d:Phone>(5) 555-4729</d:Phone> <d:Fax>(5) 555-3745</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>ANTON</d:CustomerID> <d:CompanyName>Antonio Moreno Taquería</d:CompanyName> <d:ContactName>Antonio Moreno</d:ContactName> <d:ContactTitle>Owner</d:ContactTitle> <d:Address>Mataderos 2312</d:Address> <d:City>México D.F.</d:City> <d:Region m:null="true" /> <d:PostalCode>05023</d:PostalCode> <d:Country>Mexico</d:Country> <d:Phone>(5) 555-3932</d:Phone> <d:Fax m:null="true" /> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>AROUT</d:CustomerID> <d:CompanyName>Around the Horn</d:CompanyName> <d:ContactName>Thomas Hardy</d:ContactName> <d:ContactTitle>Sales Representative</d:ContactTitle> <d:Address>120 Hanover Sq.</d:Address> <d:City>London</d:City> <d:Region m:null="true" /> <d:PostalCode>WA1 1DP</d:PostalCode> <d:Country>UK</d:Country> <d:Phone>(171) 555-7788</d:Phone> <d:Fax>(171) 555-6750</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BERGS</d:CustomerID> <d:CompanyName>Berglunds snabbköp</d:CompanyName> <d:ContactName>Christina Berglund</d:ContactName> <d:ContactTitle>Order Administrator</d:ContactTitle> <d:Address>Berguvsvägen 8</d:Address> <d:City>Luleå</d:City> <d:Region m:null="true" /> <d:PostalCode>S-958 22</d:PostalCode> <d:Country>Sweden</d:Country> <d:Phone>0921-12 34 65</d:Phone> <d:Fax>0921-12 34 67</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BLAUS</d:CustomerID> <d:CompanyName>Blauer See Delikatessen</d:CompanyName> <d:ContactName>Hanna Moos</d:ContactName> <d:ContactTitle>Sales Representative</d:ContactTitle> <d:Address>Forsterstr. 57</d:Address> <d:City>Mannheim</d:City> <d:Region m:null="true" /> <d:PostalCode>68306</d:PostalCode> <d:Country>Germany</d:Country> <d:Phone>0621-08460</d:Phone> <d:Fax>0621-08924</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BLONP</d:CustomerID> <d:CompanyName>Blondesddsl père et fils</d:CompanyName> <d:ContactName>Frédérique Citeaux</d:ContactName> <d:ContactTitle>Marketing Manager</d:ContactTitle> <d:Address>24, place Kléber</d:Address> <d:City>Strasbourg</d:City> <d:Region m:null="true" /> <d:PostalCode>67000</d:PostalCode> <d:Country>France</d:Country> <d:Phone>88.60.15.31</d:Phone> <d:Fax>88.60.15.32</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BOLID</d:CustomerID> <d:CompanyName>Bólido Comidas preparadas</d:CompanyName> <d:ContactName>Martín Sommer</d:ContactName> <d:ContactTitle>Owner</d:ContactTitle> <d:Address>C/ Araquil, 67</d:Address> <d:City>Madrid</d:City> <d:Region m:null="true" /> <d:PostalCode>28023</d:PostalCode> <d:Country>Spain</d:Country> <d:Phone>(91) 555 22 82</d:Phone> <d:Fax>(91) 555 91 99</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BONAP</d:CustomerID> <d:CompanyName>Bon app\'</d:CompanyName> <d:ContactName>Laurence Lebihan</d:ContactName> <d:ContactTitle>Owner</d:ContactTitle> <d:Address>12, rue des Bouchers</d:Address> <d:City>Marseille</d:City> <d:Region m:null="true" /> <d:PostalCode>13008</d:PostalCode> <d:Country>France</d:Country> <d:Phone>91.24.45.40</d:Phone> <d:Fax>91.24.45.41</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BOTTM</d:CustomerID> <d:CompanyName>Bottom-Dollar Markets</d:CompanyName> <d:ContactName>Elizabeth Lincoln</d:ContactName> <d:ContactTitle>Accounting Manager</d:ContactTitle> <d:Address>23 Tsawassen Blvd.</d:Address> <d:City>Tsawassen</d:City> <d:Region>BC</d:Region> <d:PostalCode>T2F 8M4</d:PostalCode> <d:Country>Canada</d:Country> <d:Phone>(604) 555-4729</d:Phone> <d:Fax>(604) 555-3745</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>BSBEV</d:CustomerID> <d:CompanyName>B\'s Beverages</d:CompanyName> <d:ContactName>Victoria Ashworth</d:ContactName> <d:ContactTitle>Sales Representative</d:ContactTitle> <d:Address>Fauntleroy Circus</d:Address> <d:City>London</d:City> <d:Region m:null="true" /> <d:PostalCode>EC2 5NT</d:PostalCode> <d:Country>UK</d:Country> <d:Phone>(171) 555-1212</d:Phone> <d:Fax m:null="true" /> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>CACTU</d:CustomerID> <d:CompanyName>Cactus Comidas para llevar</d:CompanyName> <d:ContactName>Patricio Simpson</d:ContactName> <d:ContactTitle>Sales Agent</d:ContactTitle> <d:Address>Cerrito 333</d:Address> <d:City>Buenos Aires</d:City> <d:Region m:null="true" /> <d:PostalCode>1010</d:PostalCode> <d:Country>Argentina</d:Country> <d:Phone>(1) 135-5555</d:Phone> <d:Fax>(1) 135-4892</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>CENTC</d:CustomerID> <d:CompanyName>Centro comercial Moctezuma</d:CompanyName> <d:ContactName>Francisco Chang</d:ContactName> <d:ContactTitle>Marketing Manager</d:ContactTitle> <d:Address>Sierras de Granada 9993</d:Address> <d:City>México D.F.</d:City> <d:Region m:null="true" /> <d:PostalCode>05022</d:PostalCode> <d:Country>Mexico</d:Country> <d:Phone>(5) 555-3392</d:Phone> <d:Fax>(5) 555-7293</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>CHOPS</d:CustomerID> <d:CompanyName>Chop-suey Chinese</d:CompanyName> <d:ContactName>Yang Wang</d:ContactName> <d:ContactTitle>Owner</d:ContactTitle> <d:Address>Hauptstr. 29</d:Address> <d:City>Bern</d:City> <d:Region m:null="true" /> <d:PostalCode>3012</d:PostalCode> <d:Country>Switzerland</d:Country> <d:Phone>0452-076545</d:Phone> <d:Fax m:null="true" /> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>COMMI</d:CustomerID> <d:CompanyName>Comércio Mineiro</d:CompanyName> <d:ContactName>Pedro Afonso</d:ContactName> <d:ContactTitle>Sales Associate</d:ContactTitle> <d:Address>Av. dos Lusíadas, 23</d:Address> <d:City>Sao Paulo</d:City> <d:Region>SP</d:Region> <d:PostalCode>05432-043</d:PostalCode> <d:Country>Brazil</d:Country> <d:Phone>(11) 555-7647</d:Phone> <d:Fax m:null="true" /> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>CONSH</d:CustomerID> <d:CompanyName>Consolidated Holdings</d:CompanyName> <d:ContactName>Elizabeth Brown</d:ContactName> <d:ContactTitle>Sales Representative</d:ContactTitle> <d:Address>Berkeley Gardens 12 Brewery</d:Address> <d:City>London</d:City> <d:Region m:null="true" /> <d:PostalCode>WX1 6LT</d:PostalCode> <d:Country>UK</d:Country> <d:Phone>(171) 555-2282</d:Phone> <d:Fax>(171) 555-9199</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>DRACD</d:CustomerID> <d:CompanyName>Drachenblut Delikatessen</d:CompanyName> <d:ContactName>Sven Ottlieb</d:ContactName> <d:ContactTitle>Order Administrator</d:ContactTitle> <d:Address>Walserweg 21</d:Address> <d:City>Aachen</d:City> <d:Region m:null="true" /> <d:PostalCode>52066</d:PostalCode> <d:Country>Germany</d:Country> <d:Phone>0241-039123</d:Phone> <d:Fax>0241-059428</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>DUMON</d:CustomerID> <d:CompanyName>Du monde entier</d:CompanyName> <d:ContactName>Janine Labrune</d:ContactName> <d:ContactTitle>Owner</d:ContactTitle> <d:Address>67, rue des Cinquante Otages</d:Address> <d:City>Nantes</d:City> <d:Region m:null="true" /> <d:PostalCode>44000</d:PostalCode> <d:Country>France</d:Country> <d:Phone>40.67.88.88</d:Phone> <d:Fax>40.67.89.89</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>EASTC</d:CustomerID> <d:CompanyName>Eastern Connection</d:CompanyName> <d:ContactName>Ann Devon</d:ContactName> <d:ContactTitle>Sales Agent</d:ContactTitle> <d:Address>35 King George</d:Address> <d:City>London</d:City> <d:Region m:null="true" /> <d:PostalCode>WX3 6FW</d:PostalCode> <d:Country>UK</d:Country> <d:Phone>(171) 555-0297</d:Phone> <d:Fax>(171) 555-3373</d:Fax> </m:properties> </content> </entry> <entry> <title type="text"></title> <updated>2011-11-30T11:39:28Z</updated> <author> <name /> </author> <content type="application/xml"> <m:properties> <d:CustomerID>ERNSH</d:CustomerID> <d:CompanyName>Ernst Handel</d:CompanyName> <d:ContactName>Roland Mendel</d:ContactName> <d:ContactTitle>Sales Manager</d:ContactTitle> <d:Address>Kirchgasse 6</d:Address> <d:City>Graz</d:City> <d:Region m:null="true" /> <d:PostalCode>8010</d:PostalCode> <d:Country>Austria</d:Country> <d:Phone>7675-3425</d:Phone> <d:Fax>7675-3426</d:Fax> </m:properties> </content> </entry> </feed>';
    
                // prepare the data
                var source =
                {
                    datatype: "xml",
                    datafields: [
                        { name: 'CompanyName', map: 'm\\:properties>d\\:CompanyName', type: 'string' },
                        { name: 'ContactName', map: 'm\\:properties>d\\:ContactName', type: 'string' },
                        { name: 'ContactTitle', map: 'm\\:properties>d\\:ContactTitle', type: 'string' },
                        { name: 'City', map: 'm\\:properties>d\\:City', type: 'string' },
                        { name: 'PostalCode', map: 'm\\:properties>d\\:PostalCode', type: 'string' },
                        { name: 'Country', map: 'm\\:properties>d\\:Country', type: 'string' }
                    ],
                    root: "entry",
                    record: "content",
                    id: 'm\\:properties>d\\:CustomerID',
                    localdata: customersData
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                // Create jqxGrid
                $("#jqxgrid").jqxGrid(
                {
                    width: 670,
                    source: dataAdapter,
                    columnsresize: true,
                    columns: [
                      { text: 'Company Name', datafield: 'CompanyName', width: 250 },
                      { text: 'Contact Name', datafield: 'ContactName', width: 150 },
                      { text: 'Contact Title', datafield: 'ContactTitle', width: 180 },
                      { text: 'City', datafield: 'City', width: 120 },
                      { text: 'Postal Code', datafield: 'PostalCode', width: 90 },
                      { text: 'Country', datafield: 'Country', width: 100 }
                    ]
                });
            });
        </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,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    dqninh09@gmail.com
    Participant

    hi Peter,

    I know that I am a pain on the neck, but the sample you gave out is of course working only if you have the data on the client site (or hard-code it locally inside the script like you did. But in the real world it does not work that way.

    I know that you cannot create all scenario. But, if jqwidgets claims to work with MVC, XML, binding remotely, and then it should have at least one example for MVC. In the MVC’s world, people would read data from the controller and return view(). That is the example (and scenario) that most people would looking for.

    But thank you so much anyway. You are great technical supporter.


    dqninh09@gmail.com
    Participant

    For more information, here is my result method in Controller

    public ActionResult GetXmlData2()
    {
    this.ServiceDocument = GetData();
    return View(this.ServiceDocument.Root);
    return View(this.ServiceDocument.Root.ToString(SaveOptions.DisableFormatting));
    }

    And here is my jqxDataAdapter

    var source =
    {
    datatype: “xml”,
    root: “MCNDATA”,
    record: “Record”,
    url: ‘@Url.Action(“GetXmlData2”, “Home”)’,
    };

    As soon as the url is not set to a file, it does not work. I debugged and indeed the GetXmlData2() is called correctly, and the method return a valid Xml (basically the same xml from the same file)

    Thanks.


    Peter Stoev
    Keymaster

    Hi dqninh,

    There are help topics about using jQWidgets with MVC which are available on the Documentation page – ASP .NET Integration section. If you would like, take a look at it. I hope that you understand that it does not really matter whether the data is read from a Controller or from a File for the Client Side.

    Best Regards,
    Peter Stoev

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

    DataTable – Problem with reading XML data #49552

    dqninh09@gmail.com
    Participant

    Thanks Peter.

    Finally, I figured it now. Even though that the data source is set to “xml”, it expected a string to return. I change the GetXmlData2() function to return a string type as shown below, and it works beautifully.

    public string GetXmlData2()
    {
    this.ServiceDocument = GetData();
    return View(this.ServiceDocument.Root.ToString());
    }

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

You must be logged in to reply to this topic.