2012-09-03 43 views
0

我是jqgrid的入門者。我有一個jqgrid和頁面中的按鈕。我想用戶編輯行示例row1,row2,row3,...,並點擊按鈕,當點擊按鈕發送數據行1,2,3到服務器。但jqGrid在用戶編輯行時向服務器發送數據。請給我解決我的問題。感謝所有在jqgrid中使用內聯編輯時,如何將所有數據發送到服務器

我寫這篇文章的代碼

var mydata = [ 
{ id: "1", REQUEST_ID: "2007-10-01", WAYBILL_NO: "test", COST_ID: "note", COST_NAME: "200.00", COST_AMOUNT: "10.00", Subcategory: "1" }, 
{ id: "2", REQUEST_ID: "2007-10-02", WAYBILL_NO: "test2", COST_ID: "note2", COST_NAME: "300.00", COST_AMOUNT: "20.00", Subcategory: "2" }, 
{ id: "3", REQUEST_ID: "2007-09-01", WAYBILL_NO: "test3", COST_ID: "note3", COST_NAME: "400.00", COST_AMOUNT: "30.00", Subcategory: "1" }, 
{ id: "12", REQUEST_ID: "2007-09-10", WAYBILL_NO: "test11", COST_ID: "note12", COST_NAME: "500.00", COST_AMOUNT: "30.00", Subcategory: "1" } 
]; 



      var localstr = "0:Select Ones;"; 
      localstr += "1:Dollar"; 
      localstr += ";2:Pond"; 
      localstr += ";3:Youro"; 
      localstr += ";4:Derham"; 

      var lastSel; 
      var grid = jQuery("#list"); 
      grid.jqGrid({ 

       datatype: "local", 
       data: mydata, 
       ajaxGridOptions: { cache: false }, 
       loadonce: true, 
       direction: "rtl", 


       height: 'auto', 
       colNames: ['RequestID', 'WayBillNo', 'CostId', 'CostName', 'Amount', 'CurrencyUnit '], 
       colModel: [ 
        { name: 'REQUEST_ID', width: 100, sortable: true, hidden: true }, 
         { name: 'WAYBILL_NO', width: 100, sortable: true, hidden: true }, 
         { name: 'COST_ID', index: 'COST_ID', width: 200, sortable: true, hidden: true }, 
         { name: 'COST_NAME', width: 200, sortable: true }, 
         { name: 'COST_AMOUNT', width: 100, sortable: true, editable: true }, 
         { name: 'Subcategory', index: 'Subcategory', width: 200, formatter: 'select', editable: true, edittype: 'select', editoptions: { value: localstr} } 
       ], 
       sortname: 'Name', 
       viewrecords: true, 
       rownumbers: true, 
       sortorder: "desc", 
       editurl: 'clientArray', 
       onSelectRow: function (id) { 

        if (id && id !== lastSel) { 

         grid.saveRow(lastSel, true, 'clientArray'); 

         grid.jqGrid('restoreRow', lastSel); 
         grid.jqGrid('editRow', id, true, null, null, 'clientArray'); 
         lastSel = id; 

        } 


       }, 

       pager: '#pager', 
       caption: "" 
      }).jqGrid('navGrid', '#pager', { edit: true, add: true, del: false, search: false, refresh: false }); 

但什麼是clientArray,以及如何使用數據伊諾clientArray發送到服務器? 感謝您的幫助。

回答

0

你可以存儲在該按鈕的所有數據發送到服務器,用戶點擊該創建按鈕後,所有數據都變成網格

你從電網

這個

onSelectRow: function (id) { 
        if (id && id !== lastSel) { 
         grid.jqGrid('restoreRow', lastSel); 
         grid.saveRow(lastSel,true,'clientArray'); 
         grid.jqGrid('restoreRow',lastSel); 

         grid.jqGrid('editRow', id, true, null, null, 'clientArray'); 

        } 
       }, 

和讀取數據更改代碼

$("#btnSave").click(function(){ 
    var row=$("#list").jqGrid('getRowData',1); 
alert(row.cost_id) 
}); 
相關問題