Forum
Topic RSS
00:33
20/06/2012
OfflineHello.
First of all I would like to express my deep appreciation to the grid plugin. I am a regular user.
But this time I am facing a new and challenging situation: my grid is using only LOCAL DATA.
I spent hours searching the net for a solution but I simply can't put it together, then I decided to post my question.
I am reading a database and creating a custom javascript object out of its rows. This array is being used by some other codes to display information on a map (using Google Maps api).
Someone requested the data should also be displayed on a table and then here I am, trying to populate my grid with the current loaded array of objects.
The grid columns are defined by this:
colModel:[
{name:'id',index:'id', width:50, editable:false},
{name:'vehicle',index:'vehicle', width:110, editable:false},
{name:'select',index:'select', width:30, editable:false}, //will be used to select rows
]
The array of objects is accessed by:
mvs.getVehicles();
And the values for each column relies in:
var v = mvs.getVehicles[x];
column ID is v.devid
column Vehicle is v.name
Please shed some light on me.
Thanks a million,
Paulo Pedroso
08:58
14/06/2012
Offline15:27
20/06/2012
OfflineHi Pradeep.
I forgot to mention I am trying to find a way to do this without adding row by row. I found a way that is working for me so far and this involves transforming by object back to Json. I wonder if there's a way to map the columns to some data.
Here is what I did:
I am using this library to convert my object back to Json:
https://github.com/douglascrockford/JSON-js/blob/master/json2.js
Then I had to add a prototype to my objecy like this (right now I am using just a few fields and not diggin into other objects in my object):
var returnObj = new Object();
returnObj.devid = this.devid;
returnObj.name = this.name;
returnObj.speed = this.speed;
returnObj.status = this.status;
returnObj.distanceToAddress = parseFloat(this.distanceToAddress); //Google Maps stuff
returnObj.distanceAsString = this.distanceAsString; //Google Maps stuff
return returnObj;
}
By doing this I am telling the json2 how to build json out of my object.
Then, to generate the json:
And my grid setup become like this:
datastr: vehiclesJson,
datatype: "jsonstring",
jsonReader : {
root: "vehicles",
page: function(obj){return 1;},
total: function(obj){return 1;},
records: function(mvs){return mvs.vehicles.length},
repeatitems: false,
cell: "cell",
id: "devid",
},
This is how I managed it to work out fine. But I wonder if there's a way to accomplish the same result without converting the object back to json.
Thanks,
Paulo
Most Users Ever Online: 994
Currently Online:
18 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66
Log In
Home