如何在带有可编辑复选框的jq网格中获取选定的复选框行ID [英] how to get selected checkbox row id in jq grid with editable checkbox
问题描述
var data = [[48803,"true"], [48769,"true"]];
$("#grid").jqGrid({
datatype: "local",
height: 250,
colNames: ['Inv No','MyPrint'],
colModel: [{
name: 'id',
index: 'id',
width: 60,
sorttype: "int"},
{
name: 'MyPrint',
index: 'MyPrint',
width: 80,
editoptions: { value: "True:False" },
editrules: { required: true },
edittype: 'checkbox',
formatter: myPrintCheckboxFormatter,
formatoptions: { disabled: false },
editable: true }
],
caption: "test example"
});
var names = ["id","true"];
var mydata = [];
for (var i = 0; i < data.length; i++) {
mydata[i] = {};
for (var j = 0; j < data[i].length; j++) {
mydata[i][names[j]] = data[i][j];
}
}
for (var i = 0; i <= mydata.length; i++) {
$("#grid").jqGrid('addRowData', i + 1, mydata[i]);
}
function myPrintCheckboxFormatter(cellvalue, options, rowObject) {
//how to pass currently selcted id of row
return "<input type='checkbox' name='MyPrint' onchange='getCurrentBinRow()'>";
}
function getCurrentBinRow() {
/*here I want to get the current selected MyPrint row*/
var id= $('#grid').jqGrid('getGridParam', 'selrow'); // id becomes null
}
如何检索选定的行ID ?,我试过但得到空值. 我不明白如何从onchange事件javascript函数getCurrentBinRow.it传递它,我想将已检查和未检查状态传递给服务器,如果您检查了行的CSS,则需要背景为红色,而未经检查的CSS,则需要在行中
How to retrive selected row id ?,i have tried but getting null. I does not understand how to pass it from onchange event javascript function getCurrentBinRow.i want to pass checked and unchecked status to server and if you checked the css of row need to background red and after unchecked css need to at row
推荐答案
您可以执行以下操作:
function myPrintCheckboxFormatter(cellvalue, options, rowObject) {
return "<input type='checkbox' name='MyPrint' onchange='getCurrentBinRow(this)'>";
} //---------------------------------------------------pass this in here-----^^^^
function getCurrentBinRow(elem) {
var id = $(elem).closest('tr')[0].id;
$(elem).closest('tr').toggleClass('redRow'); // adds red bgcolor when checked.
alert(id);
}
将此CSS添加到样式表中:
add this css in your stylesheet:
.redRow{ background:red !important; }
更新:
您甚至也可以这样做:
Update:
You can even do this too:
自定义格式化程序中有options
参数,其中有rowId
可用.因此您可以在onchange函数中传递options.rowId
.
You have options
param in the custom formatter where you have rowId
available in it. so you can pass options.rowId
in the onchange function.
function myPrintCheckboxFormatter(cellvalue, options, rowObject) {
return "<input type='checkbox' name='MyPrint' onchange='getCurrentBinRow(" + options.rowId + ")'>";
} //-------------------------------------------------------pass this in here-----^^^^^^^^^^^^^^
function getCurrentBinRow(rowid) {
alert(rowid);
}
这篇关于如何在带有可编辑复选框的jq网格中获取选定的复选框行ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!