2011-03-13 66 views
3

我正在使用:VS 2010,ASP.NET MVC2,jqGrid 3.8.2。jqGrid navGrid按鈕調用ASP.NET MVC視圖 - 如何?

我想讓navGrid的'編輯'按鈕在控制器中打開不同的視圖。我嘗試過很多事情都無濟於事。爲了打開選定的行,我假設我需要將該id附加到url。

jQuery('#listComponents').jqGrid({ 
    url: '/Components/Get', 
    editurl: '/Components/Edit', 
    ... 
    }).navGrid('#pagerComponents', {edit:true, ...}, {url: '/Components/Edit'}); 

歡迎任何建議。如果我無法使用它,我會在jqGrid外部添加一個'編輯'按鈕,並執行一個普通的Html.ActionLink調用來打開不同的視圖。

謝謝!

更新

繼@奧列格的回答,我現在有以下工作完美:

jQuery('#listComponents').jqGrid(
    { 
     url: '/Components/Get/', 
     ... 
    }).navGrid('#pagerComponents', { edit: false, ...}) 
    .navButtonAdd('#pagerComponents', { 
     caption: "", 
     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 = '/Components/Edit/' + data.COMPONENTID; 
      } 
      else { 
       alert("Please select a row to edit."); 
      } 
     }}); 

回答

4

navGrid後續的選項{edit:true, ...}的形式編輯editGridRow方法的使用,所以該對話框將顯示,而不是您的MVC控制器的視圖。要有你想要的行爲應該使用{edit:false, ...}設置並添加custom button,它看起來完全像原來的「編輯」按鈕。要做到這一點,您應該使用buttonicon: "ui-icon-pencil"參數(請參見navGridsource code中的editicon默認參數)。在this answer中,您會看到代碼示例。您還可以使用$.jgrid.nav.edittitle作爲標題參數:

var grid = $("#listComponents"); 
grid.jqGrid({ 
    url: '/Components/Get', 
    editurl: '/Components/Edit', 
    ... 
}); 
grid.navGrid('#pagerComponents', {edit:false, ...}, ...); 
grid.jqGrid ('navButtonAdd', '#pagerComponents', 
    { caption: "", buttonicon: "ui-icon-pencil", title: $.jgrid.nav.edittitle, 
     onClickButton: function() { 
      var rowid = grid.jqGrid('getGridParam', 'selrow'); 
      window.location = '/Components/Edit/' + 'rowid'; 
     } 
    } 
); 
+0

謝謝你給我一個我無法解決的問題的答案。這節省了我很多時間。完美工作。 – 2011-03-15 03:17:25