Forum


17:46

01/09/2008

I have a grid that has drop down lists for each of the cells in the row. The primary issue I have is that the value of the selected option should be different that the actual description that displays in the list. For example You might have a list of employees like this:
<select>
<option value="1">Bob</option>
<option value="2">John</option>
<option value="3">Tony</option>
<option value="4">Ralph</option>
</select>
If the cell contained the value "3", then when I click on the drop down, it should position it to "Tony" (value 3). Instead, it positions it at the first value.
I load the grid with the *values* that correspond to the descriptions (eg 1,2,3,4) and I want the grid to position to the correct option in the list. But, it doesn't. The only time that the list positions to the correct value is when I have BOTH the value and description match. Like this:
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
Then if the cell has the value of 3, when the drop down list is triggered, it is already positioned at "3" in the list.
I set the drop down lists using the setColProp method:
.setColProp('emp',{edittype:"select",editoptions:employees})
In this case, the variable employees contains the name:value pairs of the employees.
Am I doing something wrong here? Positioning the list to the value, rather than the description of the select options seems like the practical way to have this work but I can't seem to make it work. I always have to have the option value and option description match the value in the cell.
Ideas? Suggestions?
Thanks
17:50

01/09/2008

Anyone?
Juan posted what I think was a similar issue in his post "trying to create to dependant dropdowns". I kind of got lost in all the code though.
This seems to be pretty standard requirement:
When you select a value from a dropdown, it retrieves the id value. When you trigger a dropdown it should postion to the id value rather than the cell value.
If I am doing something incorrect, let me know. In the example above, selecting "Tony" from the dropdown list stores "3" in the cell and displays "Tony". I just want the reverse of that to be true as well: I want the select list to position to the "3" value but display "Tony" in the cell.
Ideas?
20:34

01/09/2008

This is a bug I think. I have been looking at code and debugging for a couple of hours and narrowed it down to this code in grid.common.js (3.4.4)
At around line 191 is a line that has the following:
if (!msl && oSv[key]==vl){ ov.selected ="selected"};
oSv[key] returns the text, not the value of the hash key so if you change it to this:
if (!msl && key==vl){ ov.selected ="selected"};
Then the code works correctly.
Check my assumptions though. I am not a very strong javascript programmer. But it IS working for me not. When I click on the drop down, it positions to the initial value correctly.
03:05

Moderators
30/10/2007

Hello,
You do not need to change the code. There is a special option for this purpose in 3.4 and in 3.5 - you just need to read the docs.
colModel :[
{...... formatter:'select'...}
....
]
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.
21:07

01/09/2008

Thanks Tony. I had read the documentation but it is pretty extensive and the initial read on formatter didn't seem to fit. But those changes did make the select work like I expected. That introduced a new problem with the 'savedRow' data. I use 'savedRow' to retrieve saved row so I can pass it to my .saverow function so I can compare the "before" and "after" values in the row:
var mySavedRow = $('#subBE').getGridParam('savedRow');
But 'savedRow' now contains the text of the cell than the key value. In the example above, if I selected "Tony" the key value in the cell should be "3" and the "3" should be passed as the "savedRow" value. But I see "Tony" instead. I read through the formatter docs but this looks like something the grid should handle. I reverted my code changes back to the original but I still get the text of the cell in the "savedRow" parameter rather than the key value.
Did I miss something or do I need to use a different approach?
Thanks again.
07:15

Moderators
30/10/2007

Hello,
I have made some changes for the selects including adding a unformat for the select. Will publish this in GitHub soon.
Best 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:14

01/09/2008

BTW, I temporarily added this hack at about line 38 in grid.inlinedit.js to return the value (rather that the text) if the column type is a 'select':
$(this).append(elc);
//elc has what we want when the format type is "select". Use that value instead
if({colModel:$t.p.colModel[i]}.colModel.formatter == "select")
svr[nm]=elc.value;
//Agin IE
if($t.p.colModel[i].edittype == "select" && $t.p.colModel[i].editoptions.multiple===true && $.browser.msie) {
I am sure there is a better way, but this is working for now.
06:25

Moderators
30/10/2007

Hello,
I just posted the update to the GitHub - could you please check it and let me known what is. Also I have added unformat select which should do the job.
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:59

30/07/2009

Not yet ready to test any of this, sorry, but I've looked over the changes.
Not much to say, except that I think its doing more or less what /I/ will want (once I get there!).
A couple of observations:
In grid.celledit.js, lines 119 and following:
nm = $t.p.colModel[iCol].name.replace('.',"\\\\.");switch ($t.p.colModel[iCol].edittype) {case "select":if(!$t.p.colModel[iCol].editoptions.multiple) {v = $("#"+iRow+"_"+nm.replace('.',"\\\\.")+">option:selected",$t.rows[iRow]).val();v2 = $("#"+iRow+"_"+nm.replace('.',"\\\\.")+">option:selected",$t.rows[iRow]).text();} else {var sel = $("#"+iRow+"_"+nm.replace('.',"\\\\."),$t.rows[iRow]), selectedText = [];v = $(sel).val();
Im not sure - but those three nm.replace('.',"\\\\.") look wrong, given the definition of nm...
Also, this looks wrong:if($t.p.colModel[iCol].formatter && $t.p.colModel[iCol] == 'select') v2 = v;
Note that $t.p.colModel[iCol] is an object, so its not likely to compare == 'select'.
Not sure if you meant to check edittype (which would be redundant, you've already switched on it) or formatter (which I think would be too restrictive - what about custom formatters?).
I think the correct check is just that it *has* a formatter (ie drop the &&...).
Mark
11:08

Moderators
30/10/2007

Hello,
Thanks for this. Fixed in GitHub.
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.
19:15

19/08/2009

Hi,
Forgive my ignorance but I've never used GitHub and I see that you've made the changes in the individual
modules and I'm not sure how to concatenate them into my one grid file.
(with 3.5 I understand all modules are included in the one file when downloaded from the new download manager)
Thanks,
Jo
03:28

Moderators
30/10/2007

Hello Jo,
In this case you shoul wait for the next bugfix release.
Best 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.
09:45

Moderators
30/10/2007

Hello,
Thanks. Fixed. (not jet in GitHub)
Best 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.
Most Users Ever Online: 715
Currently Online:
157 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