2010-01-25 155 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