jQWidgets Forums

jQuery UI Widgets Forums Grid Binding JSON data to jqxGrid

This topic contains 18 replies, has 3 voices, and was last updated by  oneeyeman 11 years, 4 months ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
  • Binding JSON data to jqxGrid #47732

    oneeyeman
    Participant

    Hi, ALL,
    This is continuation from this post.
    I decided to try and use JSON for my data.
    I successfully converted my data to the JSON format using django serialization. And now here’s the problem.

    Looking at the bindingtojson.html demo file I see following code:

    
            $(document).ready(function () {
                var url = "../sampledata/beverages.txt";
    
                // prepare the data
                var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'name', type: 'string' },
                        { name: 'type', type: 'string' },
                        { name: 'calories', type: 'int' },
                        { name: 'totalfat', type: 'string' },
                        { name: 'protein', type: 'string' }
                    ],
                    id: 'id',
                    url: url
                };
    

    In my case I have the following code:

    
    <script type="text/javascript">
        var data = "{{usb_data}}";
        $(document).ready(function(){
            var source =
            {
                datatype: "json",
                datafields:
                [
                    { name: 'device_name', type: 'string' },
                    { name: 'vid_pid', type: 'string' },
                    { name: 'install', type: 'string' },
                    { name: 'disk_device', type: 'string' },
                    { name: 'volume_device', type: 'string' },
                    { name: 'usb_type', type: 'string' },
                    { name: 'vid', type: 'string' },
                    { name: 'pid', type: 'string' },
                    { name: 'hub', type: 'number' }
                ]
            };
    

    My code is missing couple parameters. What should they be? I am not getting data from the file, but passing it from the Django/Python script as variable.

    My data comes in as follows:

    
    [{&quot;pk&quot;: 1, &quot;model&quot;: &quot;displayusbdata.usb&quot;, &quot;fields&quot;: {&quot;vid&quot;: &quot;#1058&quot;, &quot;pid&quot;: &quot;#0748&quot;, &quot;evidence&quot;: 5, &quot;vol_serial5&quot;: &quot;-&quot;, &quot;vol_serial4&quot;: &quot;-&quot;, &quot;vol_serial1&quot;: &quot;                                        &quot;, &quot;vol_serial3&quot;: &quot;-&quot;, &quot;vol_serial2&quot;: &quot;-&quot;, &quot;port&quot;: 3, &quot;last_modify_regtime3&quot;: null, &quot;vol_name5&quot;: &quot;-&quot;, &quot;disk_device&quot;: null, &quot;revision&quot;: &quot;#1019&quot;, &quot;product&quot;: &quot;ses_device&quot;, &quot;vendor&quot;: &quot;wd&quot;, &quot;last_modify_regtime5&quot;: null, &quot;hub&quot;: 4, &quot;last_modify_regtimes1&quot;: null, &quot;last_modify_regtimes2&quot;: null, &quot;volume&quot;: &quot;&quot;, &quot;user&quot;: &quot;&quot;, &quot;vid_pid&quot;: null, &quot;vol_name1&quot;: &quot;&quot;, &quot;vol_name2&quot;: &quot;-&quot;, &quot;vol_name3&quot;: &quot;-&quot;, &quot;vol_name4&quot;: &quot;-&quot;, &quot;usb_type&quot;: &quot;other&quot;, &quot;volume_device&quot;: null, &quot;last_modify_regtime4&quot;: null, &quot;device_name&quot;: &quot;wd ses_device&quot;, &quot;instance_id&quot;: &quot;57583431453732444a323437&1&quot;, &quot;install&quot;: null, &quot;volume_name&quot;: &quot;&quot;, &quot;volume_guid&quot;: &quot;&quot;, &quot;user_datetime&quot;: null}}
    

    In particular I’m interested in “url” and “id” parameters.

    Thank you for the help.

    Binding JSON data to jqxGrid #47733

    Peter Stoev
    Keymaster

    Hi oneeyeman,

    This help topic: http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxgrid/jquery-grid-datasources.htm shows how to bind jqxGrid to various data sources. I suggest you to look at it before proceeding with jqxGrid.

    Best Regards,
    Peter Stoev

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

    Binding JSON data to jqxGrid #47816

    oneeyeman
    Participant

    Hi, Peter,
    I read thru the link and this is what I came up with:

    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Test</title>
    {% load staticfiles %}
    <link rel="stylesheet" href="{% static "jqwidgets-ver3.1.0/jqwidgets/styles/jqx.base.css" %}" type="text/css" />
    <script type="text/javascript" src="{% static "jquery-1.10.2.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxcore.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxdata.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxscrollbar.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.sort.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.filter.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.aggregates.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.selection.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.pager.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.grouping.js" %}"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: '&quot;device_name&quot;', type: 'string' },
                    { name: '&quot;vid_pid&quot;', type: 'date' },
                    { name: '&quot;install&quot;', type: 'date' },
                    { name: '&quot;disk_device&quot;', type: 'date' },
                    { name: '&quot;volume_device&quot;', type: 'date' },
                    { name: '&quot;usb_type&quot;', type: 'string' },
                    { name: '&quot;vid&quot;', type: 'string' },
                    { name: '&quot;pid&quot;', type: 'string' },
                    { name: '&quot;hub&quot;', type: 'number' }
                ],
                id: '&quot;pk&quot;',
                root: '&quot;fields&quot;'
            };
            var dataAdapter = new $.jqx.dataAdapter(source)
            //initialize jqxGrid
            $("#grid").jqxGrid(
            {
                source: dataAdapter,
                showstatusbar: true,
                editable: false,
                columns:
                [
                    { text: 'Device Name', columntype: 'textbox', datafield: '&quot;device_name&quot;', width: 100 },
                    { text: 'VID/PID', columntype: 'textbox', datafield: '&quot;vid_pid&quot;', width: 50 },
                    { text: 'Install', columntype: 'textbox', datafield: '&quot;install&quot;', width: 50 },
                    { text: 'Disk Device', columntype: 'textbox', datafield: '&quot;disk_device&quot;', width: 50 },
                    { text: 'Volume Device', columntype: 'textbox', datafield: '&quot;volume_device&quot;', width: 50 },
                    { text: 'Type', columntype: 'textbox', datafield: '&quot;usb_type&quot;', width: 100 },
                    { text: 'VID', columntype: 'textbox', datafield: '&quot;vid&quot;', width: 100 },
                    { text: 'PID', columntype: 'textbox', datafield: '&quot;pid&quot;', width: 100 },
                    { text: 'Hub', datafield: '&quot;hub&quot;', cellsalign: 'right', cellsformat: 'n2' }
                ]        
                caption: "Test"
            });
        });
    

    but the page is still empty.

    What am I missing?

    Thank you.

    Binding JSON data to jqxGrid #47837

    Peter Stoev
    Keymaster

    Hi oneeyeman,

    In the provided code there is:

    localdata: data
    

    However, the data is not initialized anywhere and seems to be undefined.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Binding JSON data to jqxGrid #47859

    oneeyeman
    Participant

    Peter,
    data is initialized.
    Just look at my first post in the thread…

    Thank you.

    Binding JSON data to jqxGrid #47873

    Peter Stoev
    Keymaster

    Hi oneeyeman,

    Well, it is not in the code which you pasted in your previous post which represents a full web page. I do not know where it is initialized, but if you use undefined data, then you will end up with JavaScript error. I suggest you to check our samples and help documentation before proceeding with your implementation.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Binding JSON data to jqxGrid #47888

    oneeyeman
    Participant

    Peter,
    OK, here is the complete html code for the page:

    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Test</title>
    {% load staticfiles %}
    <link rel="stylesheet" href="{% static "jqwidgets-ver3.1.0/jqwidgets/styles/jqx.base.css" %}" type="text/css" />
    <script type="text/javascript" src="{% static "jquery-1.10.2.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxcore.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxdata.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxscrollbar.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.sort.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.filter.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.aggregates.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.selection.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.pager.js" %}"></script>
    <script type="text/javascript" src="{% static "jqwidgets-ver3.1.0/jqwidgets/jqxgrid.grouping.js" %}"></script>
    <script type="text/javascript">
        var data = "{{usb_data}}";
        $(document).ready(function(){
            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: '&quot;device_name&quot;', type: 'string' },
                    { name: '&quot;vid_pid&quot;', type: 'date' },
                    { name: '&quot;install&quot;', type: 'date' },
                    { name: '&quot;disk_device&quot;', type: 'date' },
                    { name: '&quot;volume_device&quot;', type: 'date' },
                    { name: '&quot;usb_type&quot;', type: 'string' },
                    { name: '&quot;vid&quot;', type: 'string' },
                    { name: '&quot;pid&quot;', type: 'string' },
                    { name: '&quot;hub&quot;', type: 'number' }
                ],
                id: '&quot;pk&quot;',
                root: '&quot;fields&quot;'
            };
            var dataAdapter = new $.jqx.dataAdapter(source)
            //initialize jqxGrid
            $("#grid").jqxGrid(
            {
                source: dataAdapter,
                showstatusbar: true,
                editable: false,
                columns:
                [
                    { text: 'Device Name', columntype: 'textbox', datafield: '&quot;device_name&quot;', width: 100 },
                    { text: 'VID/PID', columntype: 'textbox', datafield: '&quot;vid_pid&quot;', width: 50 },
                    { text: 'Install', columntype: 'textbox', datafield: '&quot;install&quot;', width: 50 },
                    { text: 'Disk Device', columntype: 'textbox', datafield: '&quot;disk_device&quot;', width: 50 },
                    { text: 'Volume Device', columntype: 'textbox', datafield: '&quot;volume_device&quot;', width: 50 },
                    { text: 'Type', columntype: 'textbox', datafield: '&quot;usb_type&quot;', width: 100 },
                    { text: 'VID', columntype: 'textbox', datafield: '&quot;vid&quot;', width: 100 },
                    { text: 'PID', columntype: 'textbox', datafield: '&quot;pid&quot;', width: 100 },
                    { text: 'Hub', datafield: '&quot;hub&quot;', cellsalign: 'right', cellsformat: 'n2' }
                ]        
                caption: "Test"
            });
        });
    </script>
    </head>
    <body>
    <div id='jqxWidget'>
        <div id="grid"></div>
    </div>
    </body>
    </html>
    

    The data variable is initialized in the very first line of the script:

    var data = “{{usb_data}}”;

    And here is the code which I see when I go to the “View->Source” menu in IE:

    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Test</title>
     
    <link rel="stylesheet" href="/static/jqwidgets-ver3.1.0/jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="/static/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.sort.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.aggregates.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.pager.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.grouping.js"></script>
    <script type="text/javascript"> 
        var data = "[{&quot;pk&quot;: 1, &quot;model&quot;: &quot;displayusbdata.usb&quot;, &quot;fields&quot;: {&quot;vid&quot;: &quot;#1058&quot;, &quot;pid&quot;: &quot;#0748&quot;, &quot;evidence&quot;: 5, &quot;vol_serial5&quot;: &quot;-&quot;, &quot;vol_serial4&quot;: &quot;-&quot;, &quot;vol_serial1&quot;: &quot;                                        &quot;, &quot;vol_serial3&quot;: &quot;-&quot;, &quot;vol_serial2&quot;: &quot;-&quot;, &quot;port&quot;: 3, &quot;last_modify_regtime3&quot;: null, &quot;vol_name5&quot;: &quot;-&quot;, &quot;disk_device&quot;: null, &quot;revision&quot;: &quot;#1019&quot;, &quot;product&quot;: &quot;ses_device&quot;, &quot;vendor&quot;: &quot;wd&quot;, &quot;last_modify_regtime5&quot;: null, &quot;hub&quot;: 4, &quot;last_modify_regtimes1&quot;: null, &quot;last_modify_regtimes2&quot;: null, &quot;volume&quot;: &quot;&quot;, &quot;user&quot;: &quot;&quot;, &quot;vid_pid&quot;: null, &quot;vol_name1&quot;: &quot;&quot;, &quot;vol_name2&quot;: &quot;-&quot;, &quot;vol_name3&quot;: &quot;-&quot;, &quot;vol_name4&quot;: &quot;-&quot;, &quot;usb_type&quot;: &quot;other&quot;, &quot;volume_device&quot;: null, &quot;last_modify_regtime4&quot;: null, &quot;device_name&quot;: &quot;wd ses_device&quot;, &quot;instance_id&quot;: &quot;57583431453732444a323437&1&quot;, &quot;install&quot;: null, &quot;volume_name&quot;: &quot;&quot;, &quot;volume_guid&quot;: &quot;&quot;, &quot;user_datetime&quot;: null}}, {&quot;pk&quot;: 2, &quot;model&quot;: &quot;displayusbdata.usb&quot;, &quot;fields&quot;: {&quot;vid&quot;: &quot;#1058&quot;, &quot;pid&quot;: &quot;#0748&quot;, &quot;evidence&quot;: 5, &quot;vol_serial5&quot;: &quot;-&quot;, &quot;vol_serial4&quot;: &quot;-&quot;, &quot;vol_serial1&quot;: &quot;                                        &quot;, &quot;vol_serial3&quot;: &quot;-&quot;, &quot;vol_serial2&quot;: &quot;-&quot;, &quot;port&quot;: 3, &quot;last_modify_regtime3&quot;: null, &quot;vol_name5&quot;: &quot;-&quot;, &quot;disk_device&quot;: null, &quot;revision&quot;: &quot;#1019&quot;, &quot;product&quot;: &quot;ses_device&quot;, &quot;vendor&quot;: &quot;wd&quot;, &quot;last_modify_regtime5&quot;: null, &quot;hub&quot;: 4, &quot;last_modify_regtimes1&quot;: null, &quot;last_modify_regtimes2&quot;: null, &quot;volume&quot;: &quot;&quot;, &quot;user&quot;: &quot;&quot;, &quot;vid_pid&quot;: null, &quot;vol_name1&quot;: &quot;&quot;, &quot;vol_name2&quot;: &quot;-&quot;, &quot;vol_name3&quot;: &quot;-&quot;, &quot;vol_name4&quot;: &quot;-&quot;, &quot;usb_type&quot;: &quot;other&quot;, &quot;volume_device&quot;: null, &quot;last_modify_regtime4&quot;: null, &quot;device_name&quot;: &quot;wd ses_device&quot;, &quot;instance_id&quot;: &quot;575834314537325538343836&1&quot;, &quot;install&quot;: null, &quot;volume_name&quot;: &quot;&quot;, &quot;volume_guid&quot;: &quot;&quot;, &quot;user_datetime&quot;: null} }]";
        $(document).ready(function(){
            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: '&quot;device_name&quot;', type: 'string' },
                    { name: '&quot;vid_pid&quot;', type: 'date' },
                    { name: '&quot;install&quot;', type: 'date' },
                    { name: '&quot;disk_device&quot;', type: 'date' },
                    { name: '&quot;volume_device&quot;', type: 'date' },
                    { name: '&quot;usb_type&quot;', type: 'string' },
                    { name: '&quot;vid&quot;', type: 'string' },
                    { name: '&quot;pid&quot;', type: 'string' },
                    { name: '&quot;hub&quot;', type: 'number' }
                ],
                id: '&quot;pk&quot;',
                root: '&quot;fields&quot;'
            };
            var dataAdapter = new $.jqx.dataAdapter(source)
            //initialize jqxGrid
            $("#grid").jqxGrid(
            {
                source: dataAdapter,
                showstatusbar: true,
                editable: false,
                columns:
                [
                    { text: 'Device Name', columntype: 'textbox', datafield: '&quot;device_name&quot;', width: 100 },
                    { text: 'VID/PID', columntype: 'textbox', datafield: '&quot;vid_pid&quot;', width: 50 },
                    { text: 'Install', columntype: 'textbox', datafield: '&quot;install&quot;', width: 50 },
                    { text: 'Disk Device', columntype: 'textbox', datafield: '&quot;disk_device&quot;', width: 50 },
                    { text: 'Volume Device', columntype: 'textbox', datafield: '&quot;volume_device&quot;', width: 50 },
                    { text: 'Type', columntype: 'textbox', datafield: '&quot;usb_type&quot;', width: 100 },
                    { text: 'VID', columntype: 'textbox', datafield: '&quot;vid&quot;', width: 100 },
                    { text: 'PID', columntype: 'textbox', datafield: '&quot;pid&quot;', width: 100 },
                    { text: 'Hub', datafield: '&quot;hub&quot;', cellsalign: 'right', cellsformat: 'n2' }
                ]        
                caption: "Test"
            });
        });
    </script>
    </head>
    <body>
    <div id='jqxWidget'>
        <div id="grid"></div>
    </div>
    </body>
    </html>
    

    Do you see a problem with the code or do you want more code?
    If you do, please tell me what it is and I will post it.

    Thank you.

    Binding JSON data to jqxGrid #47890

    Peter Stoev
    Keymaster

    caption: “Test” is invalid code.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Binding JSON data to jqxGrid #47891

    oneeyeman
    Participant

    Peter,
    I removed that line but still getting “Error on page”, the page is still empty and server terminal shows following:

    
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/styles/jqx.base
    .css HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jquery-1.10.2.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxcore.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxdata.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxscrollbar.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.sort.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.filter.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.pager.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.selection.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.aggregates.js HTTP/1.1" 304 0
    [15/Jan/2014 02:32:19] "GET /static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.grouping.js HTTP/1.1" 304 0
    

    What is this “304” error?
    I restarted my server and receive those errors….
    Maybe that’s why I’m getting “Error on page”?

    Thank you.

    [EDIT]
    I didn’t touch anything on the server or the client side. Just remove the offending line.
    But sometimes I did get that same error even before.
    [/EDIT]

    Binding JSON data to jqxGrid #47893

    Peter Stoev
    Keymaster

    Hi oneeyeman,

    I don’t have idea what is 304 error. Check whether the references path is correct or whether that is the correct way to add references in Django.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Binding JSON data to jqxGrid #47975

    oneeyeman
    Participant

    Hi, Peter,
    I cleaned my IE cache, restarted the server and tried to go to the page again.
    I now get the 200 responce on the server log, but the page is still empty.

    What else can I try?
    Is my script OK?

    Thank you.

    Binding JSON data to jqxGrid #48048

    oneeyeman
    Participant

    Hi, Peter,
    I got rid of the ugly "&quot;" text.
    So now my page code looks like this:

    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Test</title>
     
    <link rel="stylesheet" href="/static/jqwidgets-ver3.1.0/jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="/static/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.sort.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.filter.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.aggregates.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.pager.js"></script>
    <script type="text/javascript" src="/static/jqwidgets-ver3.1.0/jqwidgets/jqxgrid.grouping.js"></script>
    <script type="text/javascript"> 
        var data = "[{"pk": 1, "model": "displayusbdata.usb", "fields": {"vid": "#1058", "pid": "#0748", "evidence": 5, "vol_serial5": "-", "vol_serial4": "-", "vol_serial1": "                                        ", "vol_serial3": "-", "vol_serial2": "-", "port": 3, "last_modify_regtime3": null, "vol_name5": "-", "disk_device": null, "revision": "#1019", "product": "ses_device", "vendor": "wd", "last_modify_regtime5": null, "hub": 4, "last_modify_regtimes1": null, "last_modify_regtimes2": null, "volume": "", "user": "", "vid_pid": null, "vol_name1": "", "vol_name2": "-", "vol_name3": "-", "vol_name4": "-", "usb_type": "other", "volume_device": null, "last_modify_regtime4": null, "device_name": "wd ses_device", "instance_id": "57583431453732444a323437&1", "install": null, "volume_name": "", "volume_guid": "", "user_datetime": null}}, {"pk": 2, "model": "displayusbdata.usb", "fields": {"vid": "#1058", "pid": "#0748", "evidence": 5, "vol_serial5": "-", "vol_serial4": "-", "vol_serial1": "                                        ", "vol_serial3": "-", "vol_serial2": "-", "port": 3, "last_modify_regtime3": null, "vol_name5": "-", "disk_device": null, "revision": "#1019", "product": "ses_device", "vendor": "wd", "last_modify_regtime5": null, "hub": 4, "last_modify_regtimes1": null, "last_modify_regtimes2": null, "volume": "", "user": "", "vid_pid": null, "vol_name1": "", "vol_name2": "-", "vol_name3": "-", "vol_name4": "-", "usb_type": "other", "volume_device": null, "last_modify_regtime4": null, "device_name": "wd ses_device", "instance_id": "575834314537325538343836&1", "install": null, "volume_name": "", "volume_guid": "", "user_datetime": null}},
    # A lot more records
    ]";
        $(document).ready(function(){
            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: 'device_name', type: 'string' },
                    { name: 'vid_pid', type: 'date' },
                    { name: 'install', type: 'date' },
                    { name: 'disk_device', type: 'date' },
                    { name: 'volume_device', type: 'date' },
                    { name: 'usb_type', type: 'string' },
                    { name: 'vid', type: 'string' },
                    { name: 'pid', type: 'string' },
                    { name: 'hub', type: 'number' }
                ],
                id: 'pk',
                root: 'fields'
            };
            var dataAdapter = new $.jqx.dataAdapter(source)
            //initialize jqxGrid
            $("#grid").jqxGrid(
            {
                source: dataAdapter,
                showstatusbar: true,
                editable: false,
                columns:
                [
                    { text: 'Device Name', columntype: 'textbox', datafield: 'device_name', width: 100 },
                    { text: 'VID/PID', columntype: 'textbox', datafield: 'vid_pid', width: 50 },
                    { text: 'Install', columntype: 'textbox', datafield: 'install', width: 50 },
                    { text: 'Disk Device', columntype: 'textbox', datafield: 'disk_device', width: 50 },
                    { text: 'Volume Device', columntype: 'textbox', datafield: 'volume_device', width: 50 },
                    { text: 'Type', columntype: 'textbox', datafield: 'usb_type', width: 100 },
                    { text: 'VID', columntype: 'textbox', datafield: 'vid', width: 100 },
                    { text: 'PID', columntype: 'textbox', datafield: 'pid', width: 100 },
                    { text: 'Hub', datafield: 'hub', cellsalign: 'right', cellsformat: 'n2' }
                ]        
            });
        });
    </script>
    </head>
    <body>
    <div id='jqxWidget'>
        <div id="grid"></div>
    </div>
    </body>
    </html>
    

    It is much easier to read and comprehend.
    Do you see any problems with the code?

    Thank you.

    Binding JSON data to jqxGrid #48054

    Peter Stoev
    Keymaster

    Hi oneyeeman,

    Below is a working sample based on your data:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title id='Description'>This example shows how to create a Grid from Array data.</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/jqxdatatable.js"></script> 
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.js"></script> 
        <script type="text/javascript"> 
        $(document).ready(function(){
            var data = '[{"pk": 1, "model": "displayusbdata.usb", "fields": {"vid": "#1058", "pid": "#0748", "evidence": 5, "vol_serial5": "-", "vol_serial4": "-", "vol_serial1": "                                        ", "vol_serial3": "-", "vol_serial2": "-", "port": 3, "last_modify_regtime3": null, "vol_name5": "-", "disk_device": null, "revision": "#1019", "product": "ses_device", "vendor": "wd", "last_modify_regtime5": null, "hub": 4, "last_modify_regtimes1": null, "last_modify_regtimes2": null, "volume": "", "user": "", "vid_pid": null, "vol_name1": "", "vol_name2": "-", "vol_name3": "-", "vol_name4": "-", "usb_type": "other", "volume_device": null, "last_modify_regtime4": null, "device_name": "wd ses_device", "instance_id": "57583431453732444a323437&1", "install": null, "volume_name": "", "volume_guid": "", "user_datetime": null}}, {"pk": 2, "model": "displayusbdata.usb", "fields": {"vid": "#1058", "pid": "#0748", "evidence": 5, "vol_serial5": "-", "vol_serial4": "-", "vol_serial1": "                                        ", "vol_serial3": "-", "vol_serial2": "-", "port": 3, "last_modify_regtime3": null, "vol_name5": "-", "disk_device": null, "revision": "#1019", "product": "ses_device", "vendor": "wd", "last_modify_regtime5": null, "hub": 4, "last_modify_regtimes1": null, "last_modify_regtimes2": null, "volume": "", "user": "", "vid_pid": null, "vol_name1": "", "vol_name2": "-", "vol_name3": "-", "vol_name4": "-", "usb_type": "other", "volume_device": null, "last_modify_regtime4": null, "device_name": "wd ses_device", "instance_id": "575834314537325538343836&1", "install": null, "volume_name": "", "volume_guid": "", "user_datetime": null}}]';
            
            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: 'device_name', map: 'fields>device_name', type: 'string' },
                    { name: 'vid_pid', map: 'fields>vid_pid', type: 'date' },
                    { name: 'install', map: 'fields>install', type: 'date' },
                    { name: 'disk_device', map: 'fields>disk_device', type: 'date' },
                    { name: 'volume_device', map: 'fields>volume_device', type: 'date' },
                    { name: 'usb_type', map: 'fields>usb_type', type: 'string' },
                    { name: 'vid', map: 'fields>vid', type: 'string' },
                    { name: 'pid', map: 'fields>pid', type: 'string' },
                    { name: 'hub', map: 'fields>hub', type: 'number' }
                ],
                id: 'pk'
            };
            var dataAdapter = new $.jqx.dataAdapter(source)
            //initialize jqxGrid
            $("#grid").jqxGrid(
            {
                source: dataAdapter,
                showstatusbar: true,
                editable: false,
                columns:
                [
                    { text: 'Device Name', columntype: 'textbox', datafield: 'device_name', width: 100 },
                    { text: 'VID/PID', columntype: 'textbox', datafield: 'vid_pid', width: 50 },
                    { text: 'Install', columntype: 'textbox', datafield: 'install', width: 50 },
                    { text: 'Disk Device', columntype: 'textbox', datafield: 'disk_device', width: 50 },
                    { text: 'Volume Device', columntype: 'textbox', datafield: 'volume_device', width: 50 },
                    { text: 'Type', columntype: 'textbox', datafield: 'usb_type', width: 100 },
                    { text: 'VID', columntype: 'textbox', datafield: 'vid', width: 100 },
                    { text: 'PID', columntype: 'textbox', datafield: 'pid', width: 100 },
                    { text: 'Hub', datafield: 'hub', cellsalign: 'right', cellsformat: 'n2' }
                ]        
            });
        });
    </script>
    </head>
    <body>
    <div id='jqxWidget'>
        <div id="grid"></div>
    </div>
    </body>
    </html>

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Binding JSON data to jqxGrid #48108

    kriti
    Participant

    Hi,
    Can I use a service url inplace of “#grid” of the following code to load my data from service.
    var dataAdapter = new $.jqx.dataAdapter(source)
    //initialize jqxGrid
    $(“#grid”).jqxGrid(

    calling of a service to get data from backend is possible?

    Thanks & Regards
    Kriti

    Binding JSON data to jqxGrid #48109

    Peter Stoev
    Keymaster

    Hi Kriti,

    Yes, it’s possible. Please, look at the Data Sources help topic of jqxGrid and also the ASP .NET Integration help topics here: http://www.jqwidgets.com/jquery-widgets-documentation/

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.