columnDefs how to target _all except one target without naming every index
columnDefs how to target _all except one target without naming every index

I have my columnDefs with some targets like that
columnDefs: [
{
targets: [-1],
className: 'dt-center',
orderable: false
},
{
className: 'dt-head-center dt-body-left',
targets: ['_all']
}
],
but i want to all target to have the className: 'dt-head-center dt-body-left' and the last column to not have this class and have only the dt-center.
Its there a way to do that without naming every index like [0,1,2,3,4,5,6]?
Answers
Assuming you know the number of columns, and the index of the column you want to exclude, perhaps something like this might work?
The
Array.from
call creates an array of every number from0
tonumberOfColumns - 1
.The
filter
call then excludes the specific column from the array.Array.from() - JavaScript | MDN
Array.prototype.filter() - JavaScript | MDN
The
columnDefs.targets
docs provide all the options. The only option I see is to assign a classname to theth
you want to target. Although this seems to negate the idea of usingcolumns.className
.You can use
initComplete
to remove the undesired classnames from the last column.Kevin