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_TopicIcon
'Virtual' data mode
06/12/2013
13:40
Avatar
bosko
Member
Members
Forum Posts: 6
Member Since:
06/12/2013
sp_UserOfflineSmall Offline

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

06/12/2013
16:36
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

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.

06/12/2013
17:32
Avatar
bosko
Member
Members
Forum Posts: 6
Member Since:
06/12/2013
sp_UserOfflineSmall Offline

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

07/12/2013
12:29
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

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.

09/12/2013
10:47
Avatar
bosko
Member
Members
Forum Posts: 6
Member Since:
06/12/2013
sp_UserOfflineSmall Offline

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.

<th id='"+ts.p.id+"_"+ts.p.colModel[i].name....

Best regards,

Bosko

09/12/2013
11:04
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

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.

09/12/2013
11:11
Avatar
bosko
Member
Members
Forum Posts: 6
Member Since:
06/12/2013
sp_UserOfflineSmall Offline

Of course. I didn't try to do that. I just tried to use function for name through variable as you suggested but result is the same - sort will not work in that case.

09/12/2013
11:55
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

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.

Forum Timezone: Europe/Sofia

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.com

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

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information