有没有办法禁用 jquery DataTables 的初始排序?
我正在使用 jquery DataTables 插件。从他们的文档中:
如果启用排序,则 DataTables 将在初始化时执行第一遍排序。您可以使用此变量定义对哪些列执行排序以及排序方向。 aaSorting 数组应包含一个用于最初排序的每列的数组,其中包含列的索引和方向字符串(“asc”或“desc”)。
是否可以启用排序但在初始化时禁用第一遍排序?我目前正在服务器端进行初始排序,需要排序功能,但不需要此初始排序功能。
I'm using the jquery DataTables plugin. From their documentation:
If sorting is enabled, then DataTables will perform a first pass sort on initialisation. You can define which column(s) the sort is performed upon, and the sorting direction, with this variable. The aaSorting array should contain an array for each column to be sorted initially containing the column's index and a direction string ('asc' or 'desc').
Is it possible to have sorting enabled but disable this first pass sort on initialization? I am currently doing the initial sort server side and need sorting functionality but don't need this initial sort functionality.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我发现答案将“aaSorting”设置为空数组:
对于较新的版本数据表 (>= 1.10) 使用 order 选项:
Well I found the answer set "aaSorting" to an empty array:
For newer versions of Datatables (>= 1.10) use order option:
根据最新的 api 文档:
更多信息
As per latest api docs:
More Info
在数据表选项中输入:
这是解决方案:
"aaSorting": [[ 2, 'asc' ]],
2
表示表格将按第三列排序,asc
按升序排列。In datatable options put this:
Here is the solution:
"aaSorting": [[ 2, 'asc' ]],
2
means table will be sorted by third column,asc
in ascending order.这个问题很老了,但是如果其他人正在努力解决这个问题并且没有足够的时间找到更好的方法来解决它,这可能会有所帮助。我在使用 aaSorting": []、"order": []、"bSort": false 或 "ordering": false 时遇到了问题。在所有情况下都会出错。我还有:
禁用所有列的排序。这实际上对所有列都起作用,除了第一个忽略可排序并继续使用默认排序的列。
所以我找到了一种简单的方法来使默认的排序箭头消失。
我添加到数据表中:
现在它消失了:
This question is old, but this might help if someone else is struggling with this and doesn't have enough time to find a better way to resolve it. I had a problem using ajax where if I use
aaSorting": [], "order": [], "bSort": false or "ordering": false
. In all cases it gives an error. And I also have:to disable ordering on all columns. That actually worked on all columns except the first one that ignores the orderable and keeps using the default ordering.
So I found a rustic way to make that default ordering arrow to disappear.
I added to the datatable:
And now it is gone: