How to get a column settings (render function, sortable, searchable...)
How to get a column settings (render function, sortable, searchable...)
Link to test case: https://live.datatables.net/hovemigo/1/edit
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: I'm looking for a way to get a column's settings which we define on the column while creating the table, for example. I have found the settings() api but it's said to avoid using it and use the "public" api (for me settings() is documented and appears to be part of the public api?).
I have also found these posts :
https://datatables.net/forums/discussion/comment/127069/#Comment_127069
https://datatables.net/forums/discussion/comment/96425/#Comment_96425
One of them speaks about oAColumns, and I have managed to get the wanted settings from this. For example to get the render function :
column
.data()
.unique()
.sort()
.each(function (d, j) {
// Get the render function (we can also get bSortable from here)
var columnDataRenderFunction = this.settings()[0].aoColumns[columnIndex].mRender;
});
But this seems to be "dirty", is this the way to go or is there other ways?
columnDefs: [
{
render: DataTable.render.date(),
type: 'moment-DD/MM/YYYY',
targets: [7,8]
},
{
className: "text-center",
targets: 5,
type: 'array',
render: function (data, type, row) {
return data ? 'Oui' : 'Non';
}
},
{
className: "text-center",
render: function (data, type, row) {
return data ? 'Oui' : 'Non';
},
type: 'array',
targets: 6
},
],
Replies
column().init()
might be what you want?What you don't want to do is use the DataTables API in a rendering function. There is too much overhead - a rendering function should be treated like an interrupt (if you've every done embedded programming - get in, and get out as quickly as possible.
What is it you are looking to do?
Allan
It seems that init is was I was looking at, thank you.
I'm trying to add a custom column filter in every column header.
The idea is to have a quick filter per column with a select dropdown.
Here's the working code : https://live.datatables.net/vayohuxe/2/edit?js,output
As you can see if I comment the execution of the render function, I have the raw data results, and no the "transformed" ones, so the search filter doesn't work.
Ah yes, the search operation happens on the data returned from the rendering function when the
filter
data type is asked for (see orthogonal data). You can get that data externally usingcolumn().render()
- e.g.table.column(0).render('filter')
.Allan