2012-08-14 36 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