Selectively turning on user ordering/searching for columns with HTML5 data attributes
Selectively turning on user ordering/searching for columns with HTML5 data attributes
Description of problem:
I want to turn off user ordering and searching for all columns by default. This is something that I have achieved by setting
{"targets": "_all", "orderable": false, "searchable": false}
in columnDefs
.
So far so good. But now I want to selectively turn it back on for individual columns with HTML5 data attributes by setting data-orderable="true"
or data-searchable="true"
in <th>
inside the table header. Unfortunately this doesn't work, it seems that the above in the columnDefs
overwrites the data attributes.
The alternative right now is not to set above in columnDefs
and then litter all my templates with data-orderable="false" data-searchable="false"
attributes. That doesn't seem very elegant to me.
Is there a better way to achieve this?
Replies
I believe you are correct that the
columnDefs
take priority over the HTML5 data attributes. You can see it here:http://live.datatables.net/guceduji/1/edit
You might be interested in the columnDefs conflict resolution docs. You can use that to your advantage by placing the columns you want searchable or sortable first before the
_all
.Kevin