禁用排除除了第一个之外的每一列 [英] Disable Sorting on every column except the first one
问题描述
我目前正在使用Datatables进行自定义系统,我想禁用每栏的排序,但第一个。
我尝试使用以下代码当我添加以逗号分隔的值时,正常工作
aoColumnDefs:[
{'bSortable':false, 'aTargets':[1,2,3,4]}
],
但是我的表格列号因每个文件而异,所以我可以有3个或者12个列,我不想手动添加每个文件的值。
如果我添加的值超过我在一个文件中的列我得到以下错误,执行停止
未捕获TypeError:不能读取属性'className'未定义
那么,有没有办法我可以得到这些索引并将它们传递给函数? p>
谢谢!
您可以添加一个特定的cla ss到您不想排序的TH元素。
< table>
< thead>
< th>
...
< / th>
< th class =no-sort>
...
< / th>
< / thead>
< tbody>
...
< / tbody>
< / table>
然后,您可以在 aTargets
参数
aoColumnDefs:[
{'bSortable':false,'aTargets' no-sort']}
]
查看此处有关列特定选项的更多信息。
i'm currently using Datatables for a Custom system and i would like to disable Sort for every column but the first one.
I tried with the following code wich is working fine when i add values separated by comma
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 1, 2, 3, 4 ] }
],
But my tables column number vary for each individual file so i can have 3 or maybe 12 columns, and i don't want to have to manually add the values for each file.
If i add more values than the columns i have in one file i get the following error, and an execution stop
Uncaught TypeError: Cannot read property 'className' of undefined
So, is there any way i can get those index and pass them to the function?
Thanks!
You can add a specific class to the TH element that you do not want to be sortable.
<table>
<thead>
<th>
...
</th>
<th class="no-sort">
...
</th>
</thead>
<tbody>
...
</tbody>
</table>
And then you can specify this class in your aTargets
parameter.
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': ['no-sort'] }
]
View here for more information on the Column specific options.
这篇关于禁用排除除了第一个之外的每一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!