2010-01-25 145 views
11

我有一個自動加載行的樹形網格。目標是按樹列對網格進行排序,正好在客戶端上。jqGrid在客戶端排序

但每次我點擊排序列標題,它問題 Ajax調用進行排序,但我需要的是在就地使用本地數據排序。

我是否有不正確的網格參數,或者不在樹列上的客戶端排序樹上工作?

排序是當前的jqGrid PARAMS是:

loadonce: true, // to enable sorting on client side 
sortable: true //to enable sorting 
+0

http://stackoverflow.com/questions/1329002/jqgrid-loadonce-doesnt-work-with-asp-net – queen3 2010-01-25 13:56:08

回答

7

要獲得客戶端的排序工作,我需要調用reloadGrid電網加載後:

loadComplete: function() { 
    jQuery("#myGridID").trigger("reloadGrid"); // Call to fix client-side sorting 
} 

我沒有在我的應用程序的另一個網格上執行此操作,因爲它被配置爲使用通過另一個AJAX調用檢索的數據,而不是網格直接檢索的數據:

editurl: "clientArray" 
datatype: "local" 
+0

嗨能否請您詳細一點詳細瞭解有關#groups是什麼嗎? – DavidS 2011-07-15 13:47:43

+0

這只是網格的ID。我只是改變了ID,試圖澄清這一點。 – 2011-07-15 13:53:37

+1

謝謝你,雖然我不完全理解你的解決方案。還有Groxx的另一個答案在http://stackoverflow.com/questions/1329002/jqgrid-loadonce-doesnt-work-with-asp-net它的竅門。以防其他人感興趣... – DavidS 2011-07-15 14:16:13

2

我在jqGrid上使用客戶端排序並在選擇列表更改時檢索一組新的json數據。您需要將rowTotal設置爲大於或等於返回的行數,然後在重新加載網格之前將數據類型設置爲'json'。

// Select list value changed 
$('#alertType').change(function() { 
     var val = $('#alertType').val(); 
     var newurl = '/Data/GetGridData/' + val; 
     $("#list").jqGrid().setGridParam({ url: newurl, datatype: 'json' }).trigger("reloadGrid");   
}); 

// jqGrid setup 
$(function() { 
     $("#list").jqGrid({ 
      url: '/Data/GetGridData/-1', 
      datatype: 'json', 
      rowTotal: 2000, 
      autowidth: true, 
      height:'500px', 
      mtype: 'GET', 
      loadonce: true, 
      sortable:true, 
      ... 
      viewrecords: true, 
      caption: 'Overview', 
      jsonReader : { 
       root: "rows", 
       total: "total", 
       repeatitems: false, 
       id: "0" 
      }, 
      loadtext: "Loading data...", 
     }); 
    }); 
1
$(function() { 
     $("#list").jqGrid({ 
      url: '/Data/GetGridData/-1', 
      datatype: 'json', 
      rowTotal: 2000, 
      autowidth: true, 
      height:'500px', 
      mtype: 'GET', 
      loadonce: true, 
      sortable:true, 
      ... 
      viewrecords: true, 
      caption: 'Overview', 
      jsonReader : { 
       root: "rows", 
       total: "total", 
       repeatitems: false, 
       id: "0" 
      }, 
      loadtext: "Loading data...", 
     }); 
    }); 
+2

請解釋代碼,以便它變得更有教育意義。 – lpapp 2014-02-18 08:20:11