javascript 在 SlickGrid 中设置默认排序列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9789330/
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
Set a default sort column in SlickGrid
提问by podcastfan88
回答by Tim
On the latest version you could do this:
在最新版本上,您可以这样做:
grid.setSortColumn("myColId",true); //columnId, ascending
You can also set multiple with setSortColumn*s*
您还可以使用 setSortColumn* s*设置多个
回答by Mr.Hunt
See my solution here. This applies sort on a column initially without using Dataview.
在此处查看我的解决方案。这最初在不使用 Dataview 的情况下对列应用排序。
I think it does what you want.
我认为它可以满足您的需求。
Btw since you are using Dataview. You can also give this a try. But I have not personally tried this.
顺便说一句,因为您使用的是 Dataview。你也可以试试这个。但我没有亲自尝试过这个。
dataview.reSort()
回答by cafeakashic
I had an interesting thought which worked, and that was to just enable the multi-column header sorting (example-multi-column-sort.html), and then once the grid was loaded simulate a click() on the header row I wanted to be sorted when the grid first appeared ("time" is the name of my column I was sorting). The ID of the column headers is calculated similar to the id for the root div of the grid (at least for now :0) ):
我有一个有趣的想法,它起作用了,那就是启用多列标题排序(example-multi-column-sort.html),然后一旦加载网格,在我想要的标题行上模拟 click()在网格首次出现时进行排序(“时间”是我正在排序的列的名称)。列标题的 ID 计算类似于网格的根 div 的 id(至少现在是 :0)):
var gridId = $('#myGrid').attr("class");
gridId = '#'+gridId.replace(" ui-widget","")+'time';
$(gridId).click();
The user then can click whatever other column headers they want, but I just clicked the first one for them.
然后用户可以单击他们想要的任何其他列标题,但我只是为他们单击了第一个。