1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
<?xml version="1.0" encoding="UTF-8" ?>
<dt-option group="columns">
<name>columnDefs</name>
<summary>Set column definition initialisation properties.</summary>
<since>1.10</since>
<type type="array" />
<description>
Very similar to `dt-init columns`, this parameter allows you to assign specific options to columns in the table, although in this case the column options defined can be applied to one or more columns. Additionally, not every column need be specified, unlike `dt-init columns`.
This parameter is an array of column definition objects, where the options available exactly match those for `dt-init columns` (see below for list of options in the related links).
In addition to the column property options, `dt-init columnDefs` requires a `targets` property to be set in each definition object (`dt-init columnDefs.targets`). This `targets` property tells DataTables which column(s) the definition should be applied to. It can be:
* 0 or a positive integer - column index counting from the left
* A negative integer - column index counting from the right
* A string - class name will be matched on the TH for the column
* The string `-string _all` - all columns (i.e. assign a default)
Additionally, `targets` can be either a single option from the list above, or an array of options (the different types can be mixed in the array if required). For example `targets: [ -1, -2 ]` would target the last and second last columns in the table.
### Conflict resolution
As `dt-init columnDefs` allows columns to be defined one or more times in different column definition objects (typically to define different aspects of the columns) conflicts can arise whereby a single property might be defined with different values for the same column. Likewise, this situation could also occur when `dt-init columns` is used at the same time. DataTables uses the following rules to resolve such conflicts:
1. A property defined in `dt-init columns` will _always_ take priority over any value for that property defined in `dt-init columnDefs`.
2. Properties which are higher in the `dt-init columnDefs` array will take priority over those below.
Consider for example the following table:
```js
var table = $('#myTable').DataTable( {
columnDefs: [
{ targets: [0, 1], visible: true},
{ targets: '_all', visible: false }
]
} );
```
The first and second columns will be visible in the table while all others will be hidden.
</description>
<example title="Disable filtering on the first column"><![CDATA[
$('#example').dataTable( {
"columnDefs": [ {
"targets": 0,
"searchable": false
} ]
} );
]]></example>
<related type="option">columnDefs.targets</related>
<related type="option">columns</related>
<related type="option">columns.cellType</related>
<related type="option">columns.className</related>
<related type="option">columns.contentPadding</related>
<related type="option">columns.createdCell</related>
<related type="option">columns.data</related>
<related type="option">columns.defaultContent</related>
<related type="option">columns.name</related>
<related type="option">columns.orderable</related>
<related type="option">columns.orderData</related>
<related type="option">columns.orderDataType</related>
<related type="option">columns.render</related>
<related type="option">columns.searchable</related>
<related type="option">columns.title</related>
<related type="option">columns.type</related>
<related type="option">columns.visible</related>
<related type="option">columns.width</related>
<related type="api">column()</related>
<related type="api">columns()</related>
</dt-option>
|