jQuery jqgrid 排序列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9516473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jqgrid sort column
提问by Codyfire
Is it possible to dynamically sort one column of a jqGrid when clicking a button instead of clicking in the column name?
单击按钮而不是单击列名时,是否可以对 jqGrid 的一列进行动态排序?
回答by DisplayName
In the button click event set the sort column in the grids postdata and then call a reload on the grid
在按钮单击事件中,在网格 postdata 中设置排序列,然后在网格上调用重新加载
$('#mybutton').click(function() {
$('#yourgrid').jqGrid('setGridParam', {sortname: 'yourColumn', sortorder: 'asc'}).trigger('reloadGrid', [{page: 1}]);
});
回答by Deulis
The fourth time even luckier!. Using truein the third parameter will reload the grid for sure.
第四次更幸运!。在第三个参数中使用true肯定会重新加载网格。
$('#grid').jqGrid('sortGrid', 'id', true, 'asc');
If you don't use truein the third parameter, in the first execution, the order ('asc' or 'desc') is not updated correctly.
如果您没有在第三个参数中使用true,则在第一次执行时,订单('asc' 或 'desc')不会正确更新。
回答by Paul Phillips
A possible solution - but not pretty:
一个可能的解决方案 - 但不漂亮:
$('#grid').jqGrid('setGridParam', {sortname: 'id', sortorder: 'asc'}).trigger('reloadGrid', [{page: 1}]);
$('#gbox_grid .s-ico').css('display','none');
$('#gbox_grid #jqgh_grid_id .s-ico').css('display','');
$('#gbox_grid #jqgh_grid_id .s-ico .ui-icon-triangle-1-s').removeClass('ui-state-disabled');
as shown here
如图所示
Another way to sort by a column programatically - specifying the order:
另一种以编程方式按列排序的方法 - 指定顺序:
$('#grid').jqGrid('setGridParam', {sortorder: 'desc'});
$('#grid').jqGrid('sortGrid', 'id');
The sortGrid fires off a reload for you. It wouldn't be complete without a demo : http://jsfiddle.net/uTqD5/
sortGrid 为您触发重新加载。没有演示就不会完整:http: //jsfiddle.net/uTqD5/
Third time lucky! An undocumented feature:
第三次幸运!一个未记录的功能:
$('#grid').jqGrid('sortGrid', 'id', '', 'asc');