Jqgrid 在Jquery网格视图中添加复选框

Jqgrid 在Jquery网格视图中添加复选框,jqgrid,Jqgrid,我在页面中有以下代码,它将数据绑定到j查询网格 现在,我想在现有网格中再添加一列复选框,当我选中一些复选框并按下一些按钮时。。我需要获取所选的行值 我看过一些他们提到的关于格式化程序的教程。。。。但他们并不清楚 请帮助我实现这一目标 提前谢谢 代码: 设置选项multiselect:true,该选项将添加一列复选框。然后加上 $('#EmpTable').jqGrid('getGridParam','selarrrow')) 将返回所选id的数组。您可以使用customformatter在列中显

我在页面中有以下代码,它将数据绑定到j查询网格

现在,我想在现有网格中再添加一列复选框,当我选中一些复选框并按下一些按钮时。。我需要获取所选的行值

我看过一些他们提到的关于格式化程序的教程。。。。但他们并不清楚

请帮助我实现这一目标

提前谢谢

代码:


设置选项multiselect:true,该选项将添加一列复选框。然后加上

$('#EmpTable').jqGrid('getGridParam','selarrrow'))


将返回所选id的数组。

您可以使用
customformatter
在列中显示复选框。为此,您可以在jqGrid代码中编写如下代码

colNames: ['Id','Emp Name','Emp Checkbox'],
colModel: [
            { name: 'Id', index: 'Id', hidden: true },
            { name: 'EmpName', Index: 'EmpName', width: 80 },
            { name: 'Empchk', Index: 'Empchk', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "true:false" },
                formatter: generateEmpCheckBox, formatoptions: { disabled: false } }
          ], 
格式化程序
功能代码如下

function generateEmpCheckBox(cellvalue, options, rowObject) {
    var checkedStr = "";
    if (cellvalue == true) {
        checkedStr = " checked=checked ";
    }
    return '<input type="checkbox" onchange="UpdateEmpcheckbox(' + rowObject.Id + ',this)" value="' + cellvalue + '" ' + checkedStr + '/>';
}

function UpdateEmpcheckbox(selectedId, chkBox) {
    if ($(chkBox).prop("checked")) {
        //you can write an ajax here, to update the server
        //when the checkbox is checked
    }
    else if (!($(chkBox).prop("checked"))) {
          //you can write an ajax here to update the server
          //when the checkbox is unchecked
    }
  return false;
}
function generateEmpCheckBox(单元格值、选项、行对象){
var checkedStr=“”;
如果(cellvalue==true){
checkedStr=“checked=checked”;
}
返回“”;
}
函数更新EMPCheckbox(选择EDID、chkBox){
如果($(chkBox).prop(“选中”)){
//您可以在这里编写ajax来更新服务器
//选中复选框时
}
否则如果(!($(chkBox).prop(“选中”)){
//您可以在这里编写ajax来更新服务器
//当复选框未选中时
}
返回false;
}

Hello我添加了这个,grid附带了复选框。但问题是我需要在button click事件中获取所选行。。我怎样才能做到这一点??我们在哪里可以得到这方面的完整文档???感谢您的帮助每一行都分配了一个id。您可以通过添加一个名为“id”的列来设置它,否则jqGrid会自动将其设置为1,2,3。。。如果需要选定的行,jqGrid将返回行的id$jqGrid('getGridParam','selarrrow')返回所选id的数组。文件:
function generateEmpCheckBox(cellvalue, options, rowObject) {
    var checkedStr = "";
    if (cellvalue == true) {
        checkedStr = " checked=checked ";
    }
    return '<input type="checkbox" onchange="UpdateEmpcheckbox(' + rowObject.Id + ',this)" value="' + cellvalue + '" ' + checkedStr + '/>';
}

function UpdateEmpcheckbox(selectedId, chkBox) {
    if ($(chkBox).prop("checked")) {
        //you can write an ajax here, to update the server
        //when the checkbox is checked
    }
    else if (!($(chkBox).prop("checked"))) {
          //you can write an ajax here to update the server
          //when the checkbox is unchecked
    }
  return false;
}