Javascript jqGrid 获取当前 rowid
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10085866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jqGrid get current rowid
提问by kaze
I have a jgGrid in cellEdit mode. I need to get the current rowid, for some further processing (setting a cell to read-only depending on other values). I cant find a method for that, and the events I've tried does not fire.
我在 cellEdit 模式下有一个 jgGrid。我需要获取当前的 rowid,以进行进一步处理(根据其他值将单元格设置为只读)。我找不到一种方法,而且我尝试过的事件不会触发。
The grid definition:
网格定义:
var curRowId = -1;
$("#grid").jqGrid({
datatype: 'json',
mtype: 'GET',
colNames: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',],
colModel: [
{ name: 'a', index: 'a', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
{ name: 'b', index: 'b', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true },
{ name: 'c', index: 'c', width: 70, formatter: 'date', editable: true, editrules: { required: true }, editoptions: { dataInit: function (elem) { $(elem).datepicker(); } } },
{ name: 'd', index: 'd', width: 65, editable: true, formatter: 'date', formatoptions: { srcformat: 'H:i:s', newformat: 'ShortTime' }, editrules: { time: true} },
{ name: 'e', index: 'e', width: 80, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'f', index: 'f', width: 100, editable: true },
{ name: 'g', index: 'g', width: 80, editable: true },
{ name: 'h', index: 'h', width: 80, editable: true, editrules: { maxValue: 50} },
{ name: 'i', index: 'i', width: 120, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'j', index: 'j', width: 200, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'k', index: 'k', width: 70, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'l', index: 'l', width: 70, editable: true, editrules: { maxValue: 10} },
{ name: 'm', index: 'm', width: 25, editable: false },
{ name: 'n', index: 'n', width: 70, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
{ name: 'o', index: 'o', width: 25, editable: true, editrules: { custom: true, custom_func: chkLongitudTecken} },
{ name: 'p', index: 'p', width: 80, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition },
{ name: 'q', index: 'q', width: 80, edittype: 'select', editable: true, formatter: 'select' },
{ name: 'r', index: 'r', width: 100, editable: true, editrules: { maxValue: 50} },
{ name: 's', index: 's', width: 65, edittype: 'select', editable: true, formatter: 'select' },
],
cellEdit: true,
cellsubmit: "clientArray",
sortname: 'Datum',
sortorder: 'desc',
shrinkToFit: false,
viewrecords: true,
gridview: true,
beforeCellEdit: function (id) {
curRowId = id;
alert("Here: " + curRowId);
},
onSelectRow: function (id) {
curRowId = id;
alert("test: " + curRowId);
},
height: 400,
caption: 'My Cap'
});
You can see the events I've tried with in the code above.
您可以在上面的代码中看到我尝试过的事件。
I need the id so that I later can do something like this:
我需要 id 以便我以后可以做这样的事情:
$("#grid").setColProp("k", {
editoptions: {
value: data.opPadrag,
dataEvents: [{
type: 'change',
fn: function (e) {
alert(e.currentTarget.value);
$(e).addClass("not-editable-cell");
}
}]
}
});
回答by kaze
Found a solution:
找到了解决办法:
var selr = jQuery('#grid').jqGrid('getGridParam', 'selrow');
回答by KSanyal
jQuery('#grid').jqGrid('getGridParam', 'selrow')
will give the column data as row id used as "key". If the "key" attribute is not set to a particular grid column then the proper row id will be returned.
将列数据作为用作“键”的行 ID。如果“key”属性未设置为特定的网格列,则将返回正确的行 ID。