I am using jqgrid in my new project. In the specific case, I need to use the select element in the grid. No problems.
I define colModel and column, for example, like (from the wiki)
colModel : [
...
{name:'myname', edittype:'select', editoptions:{value:{1:'One',2:'Two'}} },
...
]
But now, when I upload my data, I would prefer the column "myname" to contain the value 1. This will not work for me, instead it should contain the value "One".
The problem is that the text part of the select element in my case is localized at the business level, where colModel is dynamically generated. Also, the data type for an object that generates data through EF 4 may not be a string. Then I have to find the correct localized text and process the data result so that the "myname" column does not contain the integer that usually takes place, and instead a string with localized text.
There is no option that you can use, so when the data contains a value that matches an option in the selection list, the grid finds this option and represents the text. Now the grid represents the value as text, and first, when I click the "Edit" button, it finds the corresponding parameter and represents the text. When I cancel the edit, it will come back to represent the value again.
I started thinking about a solution, and this is what I came up with. Please, if you know the best solution or know that there is a built-in option, do not hesitate to answer. Otherwise, here is what I did:
loadComplete: function (data) {
var colModel = grid.getGridParam('colModel');
$.each(colModel, function (index, col) {
if (col.edittype === 'select') {
$.each(grid.getDataIDs(), function (index, id) {
var row = grid.getRowData(id);
var value = row[col.name];
var editoptions = col.editoptions.value;
var startText = editoptions.indexOf(value + ':') + (value + ':').length;
var endText = editoptions.indexOf(';', startText);
if (endText === -1) { endText = editoptions.length; }
var text = editoptions.substring(startText, endText);
row[col.name] = text;
grid.setRowData(id, row);
});
}
});
}
This works, and I will leave it that way if no one comes up with a better way.