2012-07-31 60 views
2

我从网上下载这个样本的jqGrid:http://tpeczek.codeplex.com/releases/view/61796单击编辑不回传

我更新了“基础知识”的格子和一个editbutton显示了每行。点击此处并传入productID时,我想转到另一个Editpage。但是没有回传?此外,我怎样才能使产品ID显示正确的价值,因为现在它显示的产品名称(EV移动到左)

电网

<script type="text/javascript"> 
     $(document).ready(function() { 
      $('#jqgProducts').jqGrid({ 
       //url from wich data should be requested 
       url: '@Url.Action("Products")', 
       //type of data 
       datatype: 'json', 
       //url access method type 
       mtype: 'POST', 
       //columns names 
       colNames: ['Actions', 'ProductID', 'ProductName', 'SupplierID', 'CategoryID', 'QuantityPerUnit', 'UnitPrice', 'UnitsInStock'], 
       //columns model 
       colModel: [ 
        { name: 'act', index: 'act', width: 55, align: 'center', sortable: false, formatter: 'actions' }, 
        { name: 'ProductID', index: 'ProductID', align: 'left' }, 
          { name: 'ProductName', index: 'ProductName', align: 'left' }, 
          { name: 'SupplierID', index: 'SupplierID', align: 'left' }, 
          { name: 'CategoryID', index: 'CategoryID', align: 'left' }, 
          { name: 'QuantityPerUnit', index: 'QuantityPerUnit', align: 'left' }, 
          { name: 'UnitPrice', index: 'UnitPrice', align: 'left' }, 
          { name: 'UnitsInStock', index: 'UnitsInStock', align: 'left' } 
          ], 
       //pager for grid 
       pager: $('#jqgpProducts'), 
       //number of rows per page 
       rowNum: 10, 
       //initial sorting column 
       sortname: 'ProductID', 
       //initial sorting direction 
       sortorder: 'asc', 
       //we want to display total records count 
       viewrecords: true, 
       //grid height 
       height: '100%', 
       editurl: '/Edit' 
      }); 

      $('#jqgProducts').navGrid('#pagerComponents', { edit: false }). 
     navButtonAdd('#pagerComponents', { 
      caption: "fdsfsdf", 
      title: "Edit Component", 
      buttonicon: "ui-icon-pencil", 
      onClickButton: function() { 
       var id = jQuery("#listComponents").getGridParam('selrow'); 
       if (id) { 
        var data = jQuery("#listComponents").getRowData(id); 
        window.location = '/Edit/' + data.COMPONENTID; 
       } 
       else { 
        alert("Please select a row to edit."); 
       } 
      } 
     }); 





     }); 


    </script> 

回答

0

所以对你的问题的第一部分,如果你想要重定向到该行中单击编辑按钮上的特定URL,则需要使用动作格式化程序指定几件事情。我告诉你如何

http://www.ok-soft-gmbh.com/jqGrid/ActionButtons41WithoutMultiedit.htm

这里检查这个例子中,我们用行动给格式化和deloptions您可以编辑这样

editOptions指定网址:{URL:“@ Url.Action(” EditAction“)”,restoreAfterError:假}

的,哪些是可编辑他们的数据会去服务器默认的行,你需要指定编辑:同列真正想要编辑这样例如

{name:'ProductName',index:'ProductName',align:'left',editable:true},

所以现在如果你点击动作格式化程序的编辑,它会带你到“EditAction”列数据,你可以在那里使用它。

对于第二部分,这一切对我来说都很好。你能检查你从服务器上获得的数据吗?你在jqgrid中使用的字符串与jqgrid的字段名相同,否则检查fiddler或开发者工具中的响应。