Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
How to read nested json list in jqgrid
25/12/2013
05:46
Avatar
Damu
New Member
Members
Forum Posts: 1
Member Since:
25/12/2013
sp_UserOfflineSmall Offline

This is my Grid data

<script>

  $(document).ready(function (){
            var i; i=0;
    $.ajax({
        url: '/display_rpt_expectedtableSchema?rpt_step_id=<%=@rpt_step_id%>&header_data=true',
        success: function (data, st) {
            if (st == "success") {
                var columnData = jQuery.parseJSON(data)
               // for(i=0;i<columnData.source.length; i++)  {alert('how many loops'); alert(i);
                jQuery("#schemalist").jqGrid({
                    //url : '/display_rpt_expectedtableSchema?rpt_step_id=<%=@rpt_step_id%>&header_data=false',
                    datastr: columnData.source,
                    pager: '#schemaPager',
                    datatype: "jsonstring",
                    colNames: ['ExpTableName','ExpColumn', 'ExpType', 'ExpSize'],
                    cmTemplate: { title: false },
                    //colModel:ColM,
                    /*colModel:  [
                        {name:'tableName',index:'tableName', width:145,jsonmap:'columns'+'.'+i+'.'+'tableName'},
                        {name:'name',index:'name', width:145,jsonmap:'columns'+'.'+i+'.'+'name'},
                        {name:'type',index:'type', width:145,jsonmap:'columns'+'.'+i+'.'+'type'},
                        {name:'size',index:'size', width:145,jsonmap:'columns'+'.'+i+'.'+'size'}
                    ],*/
                    colModel:  [
                        {name:'tableName',index:'tableName', width:145,jsonmap:'tableName'},
                        {name:'name',index:'name', width:145,jsonmap:'name'},
                        {name:'type',index:'type', width:145,jsonmap:'type'},
                        {name:'size',index:'size', width:145,jsonmap:'size'}
                    ],

                    //jsonReader:{repeatitems: false,root:'source'+'.'+i+'.'+'columns'},
                    jsonReader:{repeatitems: false,root:'source.0.columns'},
                    rowNum: 25,
                    viewrecords: true,
                    caption: "Expected Schema",
                    height: 600,
                    width: 600,
                    //multiselect: true,
                    autoFitColumns: true,
                    loadonce: true,
                    autoencode: true,
                    shrinkToFit: false,
                    ignoreCase: true
                });

                    $("#schemalist").jqGrid('navGrid','#schemaPager',{edit:false,add:false,del:false});

            }

      //      }
        },
        error: function () {
            alert("Error with AJAX callback");
        }
    });

  });

and Here is my JSON Object

{"source":[{"id":1,"columns":[{"name":"Jdate","type":"Date","size":"0","tableName":"c1"},

{"name":"CustId","type":"Int","size":"0","tableName":"c2"},

{"name":"Jdate","type":"Date","size":"0","tableName":"c3"},

{"name":"Jdate","type":"Date","size":"0","tableName":"c4"},

{"name":"Jdate","type":"Date","size":"0","tableName":"c5"}]},

{"id":2,"columns":[{"name":"Amt","type":"Money","size":" 0","tableName":"Loan"},

{"name":"Tenure","type":"int","size":" 0","tableName":"Loan"}]},

{"id":3,"columns":[{"name":"Amt","type":"Money","size":" 0","tableName":"xyz"},

{"name":"Tenure","type":"int","size":" 0","tableName":"xyz"}]}]} 


Data displaying in grid with first list which is "ID":1 but not "id" 2,3

({"name":"Jdate","type":"Date","size":"0","tableName":"c1"},

{"name":"CustId","type":"Int","size":"0","tableName":"c2"},

{"name":"Jdate","type":"Date","size":"0","tableName":"c3"},

{"name":"Jdate","type":"Date","size":"0","tableName":"c4"},

{"name":"Jdate","type":"Date","size":"0","tableName":"c5"})


Because Here I have used JsonReader as root: 'source.0.columns'.

My requirement is to load whole json object data in the above grid (i.e have to load id '1','2','3')

I tried to loop it in jsonReader:{repeatitems: false,root:'source'+'.'+i+'.'+'columns'} by getting count of the "columns" list in the object (looping the whole the grid). But Grid is loading values for first json list and not loading other 2 lists.

Is there any other approach to load given json object with the data in grid? Is there any way to loop the jsonreader to display all the jsonlist data?

How to read this kind json data in grid. am I going in right direction?

Please help me on this.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information