javascript JQGrid 中的 onSelectRow
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24029270/
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
onSelectRow in a JQGrid
提问by p.pradnya
I have gone through the solutions given for not working onSelectRow but they could not worked for me.
我已经完成了因无法在 SelectRow 上工作而给出的解决方案,但它们对我不起作用。
I have following code :
我有以下代码:
$("#myActions_gridTable").jqGrid({
datatype:'local',
data: myActionsData,
cellsubmit: 'clientArray',
cellEdit: true,
rowNum: noOfLinesToDisplay,
pager: $("#myActions_pager"),
sortname: 'contract_Name',
viewrecords: true,
sortorder: 'asc',
autoWidth:true,
loadonce: true,
cmTemplate: { title: false },
height:'auto',
scrollrows: true,
colNames:["id","Status"],
colModel:[
{
name:'id',index:'id', jsonmap:'id', width:1,hidden:true,key:true, editable:true
},
{name:'status',index:'status', align:'center', sortable: false,
editable: true,
edittype: "select",
width: 150,
editoptions: {
value: "1:Done;2:Running"
}
}
],
onSelectRow : function(id){
console.log('inside onSelectRow');
if (id && id !== lastsel) {
$('#myActions_gridTable').restoreRow(lastsel);
$('#myActions_gridTable').editRow(id, true);
lastsel = id;
}
}
});
Here OnSelectRow does not get fired, no console.log is printed. Please help.
这里 OnSelectRow 不会被触发,也不会打印 console.log。请帮忙。
回答by Runcorn
You need to define the variable lastsel
as
您需要将变量定义lastsel
为
var lastsel;
In the above code you need to do :
在上面的代码中,您需要执行以下操作:
var lastsel;
$("#myActions_gridTable").jqGrid({
..............
..............
..............,
onSelectRow : function(id){
console.log('inside onSelectRow');
if (id && id !== lastsel) {
$('#myActions_gridTable').restoreRow(lastsel);
$('#myActions_gridTable').editRow(id, true);
lastsel = id;
}
}
Here is the working JsFiddle Demo
这是工作中的JsFiddle Demo
And could get further info here http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events.
并且可以在这里获得更多信息http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events。
回答by Oleg
One possible problem could be the usage of edittype: "select"
withoutusage of formatter: "select"
. In any way the property editoptions: { value: "1:Done;2:Running" }
seems me very suspected if you don't use formatter: "select"
.
一个可能的问题可能是edittype: "select"
不使用formatter: "select"
. 无论如何,editoptions: { value: "1:Done;2:Running" }
如果您不使用formatter: "select"
.
How looks the input data for the column "status"
? Do you use 1
and 2
or "Done"
and "Running"
? If you want to hold 1
and 2
values in the data, but you want to display the values as "Done"
and "Running"
then you should use
列的输入数据看起来如何"status"
?你使用1
and2
或"Done"
and"Running"
吗?如果你想保持1
和2
值中的数据,而是要显示的值"Done"
和"Running"
那么你应该使用
formatter: "select", edittype: "select", editoptions: {value: "1:Done;2:Running"}
The demodemonstrates it. It uses
该演示演示了它。它用
var myActionsData = [
{ id: 10, status: 1 },
{ id: 20, status: 2 }
];
as the input.
作为输入。
Alternatively one can use
或者,可以使用
var myActionsData = [
{ id: 10, status: "Done" },
{ id: 20, status: "Running" }
];
but one should use
但应该使用
edittype: "select", editoptions: {value: "Done:Done;Running:Running"}
in the case. No formatter: "select"are required in the last case: see another demo.
回答by hobbydev
OnSelectrow
is not working when cellEdit
is true.
OnSelectrow
当cellEdit
为真时不工作。
You can use onCellSelect
instead of OnSelectrow
.
您可以使用onCellSelect
代替OnSelectrow
.