2012-08-14 38 views
-1

我使用的jqGrid和我添加了一个复选框列,我希望能够得到检查行,以便我可以调用与他们的服务器...我如何获得检查行ID?

我的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> 

在此先感谢...

回答

1

你应该更好的,你多选:真的,因为我可以看到你与复选框实现的功能是选择多行。

这里是它将如何为你工作。 1.在jqgrid参数中进行多重选择:true。

  1. 添加一个按钮,你的HTML这样

按钮类型= “按钮” 值= “提交” ID = “clickMe”>提交/按钮> //启动并正常关闭的标签。

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

$( '#clickMe')上单击(函数(){ VAR selRowIds = $( '#线')的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) 
     { 
      } 

我假设你有数据类型的所有列的字符串,它们都是可编辑:真正的(你可以用colModal提到这一点,所以,如果只是模块,AppliedOn是可编辑的这是真的,所以你只能用屁股来得到这两个值点击。根据您的需要,您可以更改代码。

+0

非常感谢,我明白了这一切,除了:什么是'ActionResult'?! – YMELS 2012-08-14 13:04:41

+0

哦,这是当你使用asp.net mvc,你可以在这里指定你的返回类型。 – 2012-08-14 13:20:39

+0

我没有使用MVC,它是正常的ASP.Net ... – YMELS 2012-08-14 13:56:21

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) 
    } 
    
+0

非常感谢,但什么是ActionResult?!,这是一个ASP.Net应用程序... – YMELS 2012-08-14 13:10:30

+0

Action Result - http://msdn.microsoft.com/en-us/library/system.web.mvc。 actionresult.aspx。 ASP.NET的MVC相关类的一部分。 – StingyJack 2012-08-14 13:17:48

+0

我明白了。这是MVC特定的。我对纯ASP.NET不熟悉,但是您肯定有办法定义一个函数来响应您的'editurl'并接受所需的'id'和'oper'参数? – twoflower 2012-08-14 13:19:27