jquery数据表默认排序
我试图将默认排序设置为 jquery 数据表中的第二列。默认情况下,它按索引 0 排序。我使用的是 "aaSorting": [[ 1, "asc" ]]
语法,但它突出显示了我在初始加载时不想要的列。如何设置特定列的默认排序而不突出显示该列,就好像不涉及排序并且正在使用 0 索引列一样。
I am trying to set the default sort to the second column in my jquery datatable. It by default sorts by index 0. I am using the "aaSorting": [[ 1, "asc" ]]
syntax but it highlights the column which I don't want on initial load. How can I set the default sort of a specific column without it highlighting the column as if no sorting was involved and the 0 index column was being used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
有几个选项:
初始化 DataTables 后,删除 TBODY 中 TD 元素上的排序类。
使用 http://datatables.net/ref#bSortClasses 禁用排序类。问题在于,它将禁用用户排序请求的排序类 - 这可能是也可能不是您想要的。
让您的服务器按照所需的排序顺序输出表格,并且不要对表格应用默认排序 (
aaSorting:[]
)。There are a couple of options:
Just after initialising DataTables, remove the sorting classes on the TD element in the TBODY.
Disable the sorting classes using http://datatables.net/ref#bSortClasses . Problem with this is that it will disable the sort classes for user sort requests - which might or might not be what you want.
Have your server output the table in your required sort order, and don't apply a default sort on the table (
aaSorting:[]
).这是执行此操作的实际代码...
为了不突出显示该列,请像这样修改 CSS:
Here is the actual code that does it...
To not have the column highlighted, modify the CSS like so:
您可以使用 fnSort 函数,请参阅此处的详细信息:
http://datatables.net/api#fnSort
You can use the fnSort function, see the details here:
http://datatables.net/api#fnSort
最好的选择是禁用排序并仅按照所需的排序顺序(来自数据库或其他源)提供数据。尝试将其添加到您的“数据表”中:
“b排序”:假
Best option is to disable sorting and just feed data with desired sort order (from database or other source). Try to add this to your 'datatable':
"bSort": false
Datatables 支持此功能的 HTML5 data-* 属性。
它支持排序顺序中的多列(从 0 开始)
现在我的 jQuery 只是
$('table').DataTables();
并且我得到了按 desc / asc 排序的第二列和第三列命令。以下是我发现自己重复使用的
的其他一些不错的属性:
data-page-length="-1"
将把页面长度设置为 All(通过25 表示页面长度 25)...data-fixed-header="true"
... 猜测一下Datatables supports HTML5 data-* attributes for this functionality.
It supports multiple columns in the sort order (it's 0-based)
Now my jQuery is simply
$('table').DataTables();
and I get my second and third columns sorted in desc / asc order.Here's some other nice attributes for the
<table>
that I find myself reusing:data-page-length="-1"
will set the page length to All (pass 25 for page length 25)...data-fixed-header="true"
... Make a guess只需包含以下代码:
带有示例的完整参考文章:
https://datatables.net/examples /basic_init/table_sorting.html
Just Include the following code:
Full reference article with the example:
https://datatables.net/examples/basic_init/table_sorting.html
我也有这个问题。我使用了
stateSave
选项,这导致了这个问题。去掉这个选项,问题就解决了。
I had this problem too. I had used
stateSave
option and that made this problem.Remove this option and problem is solved.
使用它对我有用:
“顺序”:[[ 1,“ASC”]],
use this it works for me:
"order": [[ 1, "ASC" ]],
这对我有用:
This worked for me: