如何在带有可编辑复选框的jq网格中获取选定的复选框行ID

编程入门 行业动态 更新时间:2024-10-27 15:16:48
本文介绍了如何在带有可编辑复选框的jq网格中获取选定的复选框行ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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

本文发布于:2023-05-31 22:05:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/400214.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   网格   编辑   如何在   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!