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
Problem setting data option
03/08/2013
01:10
Avatar
christine_draper
Member
Members
Forum Posts: 4
Member Since:
03/08/2013
sp_UserOfflineSmall Offline

I'm trying to set the data for a grid from an array.  The code below is what I got to work, but I thought I should be able to do it by setting the data option to mydata array either when I create the grid, or using setGridParam. I'm new to this.. appreciate if you can help me understand why these other approaches don't work. 

$(function(){
var data = [ { "item":"1","title":"A title" }, { "item":"2","title":"A second title" } ];
var obj = {};
obj.dataType="local";
obj.width= 700;
obj.height=400;
obj.colNames= ["Item #", "Title"]
obj.colModel= [{name:'item',width:'50'}, {name:'title',width:'100'} ];
<!-- Shouldn't setting obj.data = data work instead of setting empty then using for loop? -->
obj.data = [];
var grid = $("#my-table").jqGrid(obj);
<!-- This is what I could get to work -->
for(var i=0;i<=mydata.length;i++) {
grid.addRowData(i+1,mydata[i]);
};
<!-- Should using setGridParam("data", data) work instead of the for loop? -->
var griddata = grid.setGridParam("data", data);
});
04/08/2013
22:40
Avatar
christine_draper
Member
Members
Forum Posts: 4
Member Since:
03/08/2013
sp_UserOfflineSmall Offline

I figured out I can set all the data at once by using:

grid.addRowData("item", mydata);

Which I hope is more efficient than adding rows individually. Still curious about why the above didnt work, but not blocked anymore.

06/08/2013
11:29
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

The code that will workmost eficently is this

var data = [ { "item":"1","title":"A title" }, { "item":"2","title":"A second title" } ];
var obj = {};
obj.datatype="local";
obj.width= 700;
obj.height=400;
obj.colNames= ["Item #", "Title"]
obj.colModel= [{name:'item',width:'50'}, {name:'title',width:'100'} ];
<!– Shouldn't setting obj.data = data work instead of setting empty then using for loop? –>
obj.data = data;
var grid = $("#my-table").jqGrid(obj);
See data parameter in the docs and datatype is set wrong
Regards

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.

06/08/2013
14:53
Avatar
christine_draper
Member
Members
Forum Posts: 4
Member Since:
03/08/2013
sp_UserOfflineSmall Offline

Ah! Thanks - it worked when I fixed the attribute name to datatype. Can't believe how long I stared at that without seeing it.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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