tonytomov/jqGrid — Issue #207: Have tableToGrid respect id column/key column when adding row data
Author: exell-christopher
Created: 2011-12-02 20:22:49+00:00
State: open

Currently the row add either uses the selectable value of the row, or the index position in the data array. Could it be changed to either use the "id" column, or "key" column if it is specified in the model? My proposed changes are below.

// Add data
var a;
for (a = 0; a < data.length; a++) {
var id = null;

// use the key column if we have one defined
// and our row has a value in that column
jQuery.each(jQuery(this).jqGrid('getGridParam', 'colModel'),
function(idx, col_def) {
if (col_def['key'] === true) {
if (data[a][col_def['name']] != undefined) {
id = data[a][col_def['name']];
}
return false;
}
}
);

// use the id column if it is defined
if (id === null) {
// use the id attr if there is one
jQuery.each(jQuery(this).jqGrid('getGridParam', 'colModel'),
function(idx, col_def) {
if (col_def['name'] && col_def['name'].toLowerCase() == 'id' ) {
if (data[a][col_def['name']] != undefined) {
id = data[a][col_def['name']];
}
return false;
}
}
);
}

// use our checkbox
if (id === null && rowIds.length > 0) {