jQuery jqGrid 默认排序顺序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3730222/
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 default sort order?
提问by Marcus Leon
It appears that the jqGrid sortname
and sortorder
properties do not actually cause your data set to be sorted - they just cause the up/down arrows to be displayed.
看起来 jqGridsortname
和sortorder
属性实际上并没有导致您的数据集被排序 - 它们只是导致显示向上/向下箭头。
How can you get your data set to sort on download?
如何让您的数据集在下载时进行排序?
The sort works well when you click the column headers but I want a default sort to be applied to our data.
当您单击列标题时,排序效果很好,但我希望对我们的数据应用默认排序。
Update: When we click the next button, the next request sorts the data.
更新:当我们单击下一步按钮时,下一个请求会对数据进行排序。
This causes a slightly confusing UI where the data loads with a down arrow on a column - and the data isn't sorted - but when you click next the data is now sorted.
这会导致用户界面略微混乱,其中数据在列上加载一个向下箭头 - 并且数据未排序 - 但是当您单击下一步时,数据现在已排序。
It seems if I omit sortname and sortorder that jqGrid still displays the sort icon - weird.
似乎如果我省略 sortname 和 sortorder jqGrid 仍然显示排序图标 - 很奇怪。
回答by Veysel Ozdemir
You might be giving the same parameter twice ( a very common mistake when copy paste progrraming :) no offenses. I do it too.)
您可能会两次提供相同的参数(复制粘贴编程时非常常见的错误:) 没有冒犯。我也这样做。)
Say you want to sort by OpeningDate descending
假设您想按 OpeningDate 降序排序
..... options ....
sortname: "OpeningDate",
sortorder: "desc", <---- assume you write this line and expect to sort descending
..... some other options ....
sortorder: "asc", <---- and this line may also be there but you may not be noticing it
..... and other options ....
the second "sortorder" option overrides the first and you will not be able to sort descending
第二个“排序顺序”选项覆盖第一个选项,您将无法按降序排序
回答by Kedarnath Calangutkar
I was facing the same problem. Use this after loading the data:
我面临同样的问题。加载数据后使用:
$("#tableId").jqGrid('sortGrid','colName', false, 'asc');
or
或者
$("#tableId").sortGrid('colName', false, 'asc');
The grid is reloaded if the boolean value is set to true. The last parameter can be 'asc' / 'desc', depending on the sort order.
如果布尔值设置为 true,则重新加载网格。最后一个参数可以是“asc”/“desc”,具体取决于排序顺序。
回答by Oleg
Try to use
尝试使用
$("#list").jqGrid('setGridParam',{ page: 1 }).trigger("reloadGrid");
or
或者
$("#list").jqGrid('setGridParam',{ rowNum: 10 }).trigger("reloadGrid");
(replace 10 to value which you define as rowNum parameter). If it will not help then post your code in your question.
(将 10 替换为您定义为 rowNum 参数的值)。如果它没有帮助,请在您的问题中发布您的代码。
回答by zdux
You might have made the same mistake as myself, which was to base my client script off of an old example which used "sortName" instead of "sortname"
您可能犯了和我一样的错误,那就是将我的客户端脚本基于使用“sortName”而不是“sortname”的旧示例
回答by zdux
the problem is (I believe) that the parameter sortName nor sidx are read when requesting the first data set
问题是(我相信)在请求第一个数据集时读取参数 sortName 和 sidx
回答by Jason Slocomb
/Cheesy Answer Alert
/俗气的回答提醒
Why not hide the sorted icon the first time you load? First time someone sorts, unhide it and things work as intended. Sounds like it was your intent to load unsorted until the user chooses a column to sort on.
为什么不在第一次加载时隐藏排序的图标?第一次有人排序,取消隐藏它,事情按预期工作。听起来您打算加载未排序的内容,直到用户选择要排序的列。