Forum

July 12th, 2025
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_TopicIcon
Load grid with addJSONData problem
02/02/2010
21:49
Avatar
mike.tihonchik
Member
Members
Forum Posts: 3
Member Since:
02/02/2010
sp_UserOfflineSmall Offline

I am using dwr Ajax to return me a List<Map<String, String>> and I am trying to load the grid.

This is how I define my grid:

jQuery('#terminalGroups').jqGrid({

datatype: 'clientSide',

colNames: ['Company','Name','Active'],

colModel: [

{name:'company', index:'company', width:500},

{name:'TG_NAME', index:'TG_NAME', width:300},

{name:'activeGroup', index:'activeGroup', width:195} ],

pager: jQuery('#terminalGroupPager'),

rowNum: 10,

rowList: [10,20,30],

sortorder: 'desc',

viewrecords: true,

imgpath: 'jquery/jqueryUI/css/sunny/images',

caption: 'Merchant Groups',

height: '490px'

});

Now, I get a structure back from Ajax call, and I want to add it using following command:

jQuery('#terminalGroups').addJSONData( result );

however, I get the JS error that "object does not support this property or method". However, if I iterate through "result" and use 

jQuery('#terminalGroups').addRowData( <%=index%>, result[<%=index%>] );

it works just fine...

What am I doing wrong on addJSONData???

03/02/2010
18:14
Avatar
HoSpiTaL_gHoSt
Belgium
Member
Members
Forum Posts: 4
Member Since:
03/02/2010
sp_UserOfflineSmall Offline

Hi. Read the jqGrid documentation, everything is explained there! addJSONData is a special method:

Populates a grid with the passed data (an array).This method should be used this way - Example: Suppose we have data from a particular webservice (jsonresponse), then
var mygrid = jQuery(”#”+grid_id)[0];
var myjsongrid = eval(”(”+jsonresponse.responseText+”)”);
mygrid.addJSONData(myjsongrid);
myjsongrid = null;
jsonresponse =null;
will populate the data to the grid. And, of course, the data in myjsongrid can be manipulated before being passed to addJSONData.

See http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods

03/02/2010
22:48
Avatar
mike.tihonchik
Member
Members
Forum Posts: 3
Member Since:
02/02/2010
sp_UserOfflineSmall Offline

Thank you for reply, but I have read that already... The problem is it does not specify much about data array (what should it look like). Here is example data what I use:

var exmpl = "[{'company':'1','TG_NAME':'1','activeGroup':'1'},{'company':'2','TG_NAME':'2','activeGroup':'2'}]";

This looks like a proper JS array to me...

04/02/2010
12:03
Avatar
HoSpiTaL_gHoSt
Belgium
Member
Members
Forum Posts: 4
Member Since:
03/02/2010
sp_UserOfflineSmall Offline

This is what your array should look like:

{
"data":[{'company':'1','TG_NAME':'1','activeGroup':'1'},{'company':'2','TG_NAME':'2','activeGroup':'2'}],
"totalRows":2,
"totalPages":1,
"page":1
}

And you should call addJSONData like this:

jQuery('#terminalGroups')[0].addJSONData( result );
05/02/2010
18:06
Avatar
mike.tihonchik
Member
Members
Forum Posts: 3
Member Since:
02/02/2010
sp_UserOfflineSmall Offline

Thank you for that information… However, i am still facing the problem. This is my code:

jQuery('#terminalGroups').jqGrid({

datatype: 'json',

colNames: ['Company','Name','Active'],

colModel: [

{name:'company', index:'company', width:500},

{name:'TG_NAME', index:'TG_NAME', width:300},

{name:'activeGroup', index:'activeGroup', width:195} ],

pager: jQuery('#terminalGroupPager'),

rowNum: 10,

rowList: [10,20,30],

sortorder: 'desc',

viewrecords: true,

imgpath: 'jquery/jqueryUI/css/sunny/images',

caption: 'Merchant Groups',

height: '490px'

});

var something = { "data":[{'company':'1','TG_NAME':'1','activeGroup':'1'},{'company':'2','TG_NAME':'2','activeGroup':'2'}], "totalRows":2, "totalPages":1, "page":1 };

jQuery('#terminalGroups')[0].addJSONData( something );

However, I get JS syntax error, and when I debug, it points to this code:

($.jgrid.useJSON===true&&typeof(JSON)==="object"&&typeof(JSON.parse)==="function")

any idea what might that be?

10/02/2010
15:26
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

You should configure your jsonReader. Please read here how this can be achieved

http://www.trirand.com/jqgridw.....#json_data

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

10/02/2010
18:16
Avatar
HoSpiTaL_gHoSt
Belgium
Member
Members
Forum Posts: 4
Member Since:
03/02/2010
sp_UserOfflineSmall Offline

Yes, I'm sorry for the confusion, the array I showed you also used a jsonReader. If you don't want/need to use a jsonReader, your array should look like this:

{
"rows":[{'company':'1','TG_NAME':'1','activeGroup':'1'},{'company':'2','TG_NAME':'2','activeGroup':'2'}],
"records":2,
"total":1,
"page":1
}
Forum Timezone: Europe/Sofia

Most Users Ever Online: 994

Currently Online:
29 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