Forum
13:40
06/12/2013
I'm using jqGrid with local data and values that should be displayed in the cells depend on couple flags that can be set on the page. Simple example would be column called 'weight' which displays unit weight but if 'Total value' check box is checked on the page than in value displayed in this cell should be calculated value base on several other parameters (i.e. num_items * weight). I managed to do this by setting 'name' option in colModel to function which returns either row or calculated value. However in this case sorting by that column is not working.
Is there any way I can use jqGrid in this 'virtual data' mode where for each column instead of direct mapping to data custom function can be used?
Regards,
Bosko
16:36
Moderators
30/10/2007
Hello,
A simple source code will be greatly appretiated, we can not help in most cases if no test case is provided.
I'm not sure if this can work, but maybe you will need to set a index property of this column in colModel.
See docs
Kind 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.
17:32
06/12/2013
Hello,
I thought also that index property might help but it didn't. Seems like problem (at least for sorting) is in fact that when function is used for column name column id is set to source of function (actually substring of it). Later on in click handler there is comparision:
this.name === tid
which compares name (function in this case) and id which is string equal to substring of function source. Reproducing this is easy. Just in any sample put name to be function. Part of my code is:
colModel: [
{ name: function(obj) {
if (total) {
return obj.values.weight;
} else {
return obj.values.weight * totalNumber;
}
}, index: "calories", label: "Weight", width: 78, align: "right", firstsortorder: 'desc', sorttype: "float" }
]
Best regards,
Bosko
12:29
Moderators
30/10/2007
Hello,
Looking into the code I see there are some things which cause this not to work.
In most cases simple solutions are best one.
You can
var myname = myNameFunction(obj);
…
..jqGrid({
…
colModel : [
...
{ name : myname ,....},
...
],
…
});
where myNameFunction is the function defined from your post in colModel
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.
10:47
06/12/2013
I agree with you that simple solutions are the best one in most cases but unfortunatelly it seems this is not the case here. This solution also cross my mind and I tried it but with same result.
Looks like grid cannot work in 'virtual mode'. Problem is in a way header cell is constructed. Namely for element id it uses 'name' value from colModel which returns function code even if it is used in proposed way.
Best regards,
Bosko
11:04
Moderators
30/10/2007
Hello,
I will say it other way- the names in colModel can not be changed dynamically.
With other words if you want to change the name by condition you will need to unload and load the grid again with the new name in colModel.
See docs for methods how unload the grid.
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.
11:55
Moderators
30/10/2007
Hello,
Of course the way I posted this will not work. It was my mistake. Sorry.
The way to do it is to define a variable and change the variable within the function.
Here is a example
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.
Most Users Ever Online: 715
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66