columndef vs columns
columndef vs columns
montoyam
Posts: 568Questions: 136Answers: 5
in DataTables
I saw a post where someone was using both columndef AND columns:
https://datatables.net/forums/discussion/71535/how-to-pass-record-from-table-to-partial-view#latest
Is there an advantage to doing it this way? Or would it be better to use only one of these?
This question has an accepted answers - jump to answer
Answers
The answer is it depends
The
columns
option is generally used when defining options for each column, likecolumns.data
. In this case the advantage ofcolumnDefs
is to apply the same config options to multiple columns. The code in the thread you linked could be reduced to this:The first one, using
columnDefs.targets
[0]
, is not needed as those are all default values.columnDefs
is also useful when you aren't usingcolumns
to define all the columns. Otherwise you will need to do something like thecolumns
example.You will want to understand the columnDefs conflict resolution rules.
HTH,
Kevin
ah, i see. so even if you are using columns.data to define the columns, it could be a timesaver to not define other properties there if they are shared by other columns. you would use columnDefs to group columns with the same properties. so that is a case where you would use both methods, like in your example.
very interesting. time to go through all my projects and do some code cleanup.
If it ain't broke - don't fix it
Kevin