-1

我正在使用 jqGrid,并添加了一个复选框列,我希望能够获得选中的行,以便我可以使用它们调用服务器......

我的 jqGrid 代码:

<script type="text/javascript">
    $(function () {
        $("#UsersGrid").jqGrid({
            url: "Handler.ashx",
            datatype: 'json',
            height: '100%',
            width: '500',
            colNames: [' ', 'ref#', 'Module', 'TT#', 'AssignedOn', 'TrialNo'],
            colModel: [
                    { name: ' ', index: 'ChkBox', width: 16, sortable: false, editable: true, formatter: "checkbox", formatoptions: { disabled: false }, editable: true, edittype: "checkbox" },
                    { name: 'ref#', width: 50, sortable: true },
                    { name: 'Module', width: 50, sortable: true },
                    { name: 'TT#', width: 110, sortable: true },
                    { name: 'AssignedOn', width: 110, sortable: true },
                    { name: 'TrialNo', width: 50, sortable: true }
                ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#UsersGridPager',
            sortname: ' ',
            viewrecords: true,
            sortorder: 'asc'
            //caption: "Cases"
        });

        $("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false });
</script>

提前致谢...

4

2 回答 2

1

您不必手动添加复选框列。这是我的做法:

  1. 指定editurlmultiselect选项:

    $("#UsersGrid").jqGrid({
      // The grid will send modification data to this url
      //     
      editurl: "url which will handle the edit/delete operations",
      // This ensures there will be a checkbox column in your grid
      //
      multiselect: true,
      ...
    });
    
  2. 为修改操作提供处理程序(响应editurl请求)。在我的例子中,它是一个带有这个签名的动作方法:

    public ActionResult EditItems(string id, string oper, string source, string target)
    {
        // id: list of IDs of the selected items (e.g. "1234,5678")
        // oper: the requested operation ("edit" or "del", if you use the standard ones)
        // source, target: in case of the "edit" operation, these are the new values of the respective columns. I.e. these parameters are model-specific (I have "source" and "target" columns in my grid)
    }
    
于 2012-08-14T10:33:21.837 回答
1

您应该更好地选择:true,因为我可以看到您使用复选框实现的功能是选择多行。

这就是它对你的作用。1.在jqgrid参数中设置multiselect:true。

  1. 像这样在你的 html 中添加一个按钮

button type="button" value="submit" id="clickMe" >Submit /button> //正确启动和关闭标签。

  1. 现在在此按钮的单击事件上,获取所选行的数据并向您的服务器发出一个 ajax 请求。

$('#clickMe').click(function(){ var selRowIds = $('#grid').jqGrid('getGridParam', 'selarrrow');

if(selRowIds.length>0)
               {
                   for( var i=0;i<selRowIds.length;i++){
           var ref#=getCellValue(selRowIds[i],'ref#');
           var Module=getCellValue(selRowIds[i],'Module');
           var TT#=getCellValue(selRowIds[i],'TT#');


           var AssignedOn=getCellValue(selRowIds[i],'AssignedOn');
               var TrialNo=getCellValue(selRowIds[i],'TrialNo');

               $.ajax({
               type: 'POST',
               url: '@Url.Action("editMe")',
               contentType: 'application/json; charset=utf-8',
               data:JSON.stringify({ref#: ref#, Module:Module,TT#:TT#,AssignedOn:AssignedOn,TrialNo:TrialNo}),
               dataType: "json",
               success:function(){
               $('#grid').trigger("reloadGrid");
                },

                error: function () {
                       alert("error");
                    }
                }); 
                }
                }
           });

你的控制器应该是这样的

 public ActionResult editMe(string ref#, string Module, string TT#, string AssignedOn, string TrialNo)
        {
          }

我假设您将所有列的数据类型作为字符串,并且它们都是可编辑的:true(您可以使用 colModal 提及这一点。因此,如果只有 Module,AppliedOn 是可编辑的,那么您只能在按钮单击中获取这两个值。根据您的需要,您可以更改代码。

于 2012-08-14T12:31:36.667 回答