Sorting/Ordering columns using column name/data/class
Sorting/Ordering columns using column name/data/class
robertrish
Posts: 6Questions: 1Answers: 0
Hello!
I've recently implemented a DataTable using column data.
Ex.
columns: [
{ "data": "ids",
"name": "ids",
"className": "dtc_ids",
"width": "35px",
"orderable": false,
"searchable": false,
"visible": false
}
]
My questions are:
- Is there a way to use the name, data or class of the column in order to set the default column sort.
Standard implementation:
order: ['8', 'desc']
Desired Implementation:
order: ['ids', 'desc']
Or:
columns: [
{ "data": "ids",
"name": "ids",
"className": "dtc_ids",
"width": "35px",
"orderable": false,
"searchable": false,
"visible": false,
"defaultOrder": true,
"sortOrder": 'desc'
}
]
- Is there a way to send the name, data or class to the server instead of an index when clicking on the headers of the table to sort them?
I'm seeing the following in the POST when sorting the column:
sColumns: ids
iSortCol_0: 0
sSortDir_0: desc
- Is there a way to set column visibility using the name of the column instead of using its' class?
datatable.columns(['ids']).visible(true);
instead of
datatable.columns(['.dtc_ids']).visible(true);
Thank you very much for you help!
Rob
This discussion has been closed.
Replies
You might want to look at columnDefs, where "targets" enables multiple columns to be
nominated for the same conditions.
https://datatables.net/reference/option/columnDefs.targets
No - not at this time. Sorry. That is something I hope to implement in future.
No - it is index based. You can send a name using the
columns.name
option, but it won't alter the indexes.Yes - exactly as you have done in fact. You don't need the array, just give it the string. See
columns()
.Allan
Thank you, @Allan.
@tangerine,
I've tried using columnDefs for setting my parameters, but I wasn't able to use name, data or classes for them.
My DataTable doesn't have any content defined:
Everything is defined through the columns array. And since the table doesn't have any classes on its' <TH>'s, I can't set any parameters to them on load.
I can adjust the visibility of the table after it's completely loaded, but not before that:
Would you have an example on using columnDefs using names, data or classes in this scenario?
My apologies, I misread your question.
I mentally transposed your 'ids' into column indices
which I now realise was not what you intended.