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
|
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="columns">
<name>column().cache()</name>
<summary>Get the DataTables cached data for the selected column.</summary>
<since>1.10</since>
<type type="function">
<signature>column().cache( [ type ] )</signature>
<description>Obtain the data for the column from the selector</description>
<parameter type="string" name="type" default="order">
Specify which cache the data should be read from. Can take one of two values: `dt-string search` or `dt-string order`. Defaults to `order` if no value is given.
</parameter>
<returns type="DataTables.Api">DataTables API instance with data for each cell in the selected column in the result set. This is a 1D array with each entry being the data for the cells from the selected column.</returns>
</type>
<description>
DataTables caches data for searching and ordering in order for those operations to run as quickly as possible when they are required. Sometimes it can be useful to get the data that DataTables has cached for these operations, for example when creating a `select` list to provide a column based filter.
Cached data is not guaranteed to be available at any particular moment. If DataTables hasn't requested the data, it won't have been cached. This is particularly obvious when using the `-string order` option and a sort hasn't been performed on a column. Invalidation of data will also cause the cache to be removed.
It should be noted that this method is required as DataTables has the ability to use different data for its different operations (searching, ordering, display etc) - see `dt-init columns.data` and `dt-init columns.render` for further information. `dt-api columns().data()` provides access to the original data. If you aren't using orthogonal data for the different operations of DataTables, then this method is of limited used.
Please note that the order of the data in the returned array and which rows the data is obtained from (searched rows, visible rows etc) is controlled by the `dt-type selector-modifier` option of the `dt-api column()` selector used to get the selected column.
Additionally, if the selector used in `dt-api column()` matches more than one column, the result set will be truncated to a single column - the first one in the result set.
Note that this method is primarily aimed at plug-in developers who require access to the internal data that DataTables has stored.
</description>
<example title="Create a `select` which will search the table when used by the end user, on the first column of the table."><![CDATA[
var table = $('#example').DataTable();
// Create the select list and search operation
var select = $('<select />')
.appendTo(
table.column( 0 ).footer()
)
.on( 'change', function () {
table
.column( 0 )
.search( $(this).val() )
.draw();
} );
// Get the search data for the first column and add to the select list
table
.column( 0 )
.cache( 'search' )
.sort()
.unique()
.each( function ( d ) {
select.append( $('<option value="'+d+'">'+d+'</option>') );
} );
]]></example>
<related type="api">columns().cache()</related>
</dt-api>
|