Columns need to be referred to by an alias
Columns need to be referred to by an alias
In options like columDefs, the targets contains the column number. This is very unhandy when inserting a column. It means that we then have to change all the targets. A lot of work, especially when there are many columns.
Why not give the columns an alias so that we can refer to them like this: "targets: ['id', 'name']". Or even the name used in columns.data could be used to refer to. This way, we can insert or remove columns wherever we want without the hassle of changing the targets all the time.
Replies
Here, here! - surely we can refer to columns by their name...?
Found out how :-
As part of a columns[...] definition add any required field aliases - like so :-
@mainternet Your solution is nice, but doesn't work for the options. E.g.
order: [ [0,'desc'] ]
cannot be solved this way.You can assign an id to your column in HTML. Save the index in a variable and use that. If you hide columns later on you need to save the index prior to hiding them.
Here is an example:
and later on in your data table definition:
Yes, not being able to use the defined column name in the
order
configuration is a known limitation and something I want to address in future. At the moment you would need to use thecolumn()
selector to get the column by the given name and then usecolumn().index()
to get the index.Allan