|
4 | 4 | * Yet Another DataTables Column Filter - (yadcf)
|
5 | 5 | *
|
6 | 6 | * File: jquery.dataTables.yadcf.js
|
7 |
| -* Version: 0.8.8.beta.12 |
| 7 | +* Version: 0.8.8.beta.13 |
8 | 8 | *
|
9 | 9 | * Author: Daniel Reznick
|
10 | 10 | * Info: https://github.com/vedmack/yadcf
|
|
41 | 41 | Required: true (when filter_type is custom_func / multi_select_custom_func)
|
42 | 42 | Type: function
|
43 | 43 | Default value: undefined
|
44 |
| - Description: should be pointing to a function with the following signature myCustomFilterFunction(filterVal, columnVal) , where filterVal is the value from the select box and |
45 |
| - columnVal is the value from the relevant row column, this function should return true if the row matches your condition and the row should be displayed) and false otherwise |
| 44 | + Description: should be pointing to a function with the following signature myCustomFilterFunction(filterVal, columnVal, rowValues) , where filterVal is the value from the select box and |
| 45 | + columnVal is the value from the relevant row column, rowValues is an array that holds the values of the entire row, this function should return true if the row matches your condition and the row should be displayed) and false otherwise |
46 | 46 | Note: When using multi_select_custom_func as filter_type filterVal will hold an array of selected values from the multi select element
|
47 | 47 |
|
48 | 48 | * data
|
49 |
| - Required: false / true (when filter_type is custom_func / multi_select_custom_func) |
| 49 | + Required: false |
50 | 50 | Type: Array (of string or objects)
|
51 | 51 | Description: When the need of predefined data for filter is needed just use an array of strings ["value1","value2"....] (supported in select / multi_select / auto_complete filters) or
|
52 | 52 | array of objects [{value: 'Some Data 1', label: 'One'}, {value: 'Some Data 3', label: 'Three'}] (supported in select / multi_select filters)
|
53 | 53 | Note: that when filter_type is custom_func / multi_select_custom_func this array will populate the custom filter select element
|
54 |
| - |
| 54 | + |
| 55 | +* append_data_to_table_data |
| 56 | + Required: false |
| 57 | + Type: boolean |
| 58 | + Default value: undefined |
| 59 | + Description: Set it to true when you want to use the array you set in data attribute in addition to values that yadcf will grab from the table for you |
| 60 | + |
55 | 61 | * column_data_type
|
56 | 62 | Required: false
|
57 | 63 | Type: String
|
@@ -412,10 +418,6 @@ var yadcf = (function ($) {
|
412 | 418 | alert('You are trying to use filter_type: "custom_func / multi_select_custom_func" for column ' + options_arg[i].column_number + ' but there is no such custom_func attribute provided (custom_func: \"function reference goes here...\")');
|
413 | 419 | return;
|
414 | 420 | }
|
415 |
| - if (options_arg[i].data === undefined) { |
416 |
| - alert('You are trying to use filter_type: "custom_func / multi_select_custom_func" for column ' + options_arg[i].column_number + ' but there is no such data attribute provided (data: \"array of options goes here...\")'); |
417 |
| - return; |
418 |
| - } |
419 | 421 | }
|
420 | 422 | col_num_as_int = +options_arg[i].column_number;
|
421 | 423 | if (isNaN(col_num_as_int)) {
|
@@ -900,7 +902,7 @@ var yadcf = (function ($) {
|
900 | 902 |
|
901 | 903 | custom_func = getOptions(settingsDt.oInstance.selector)[col_num].custom_func;
|
902 | 904 |
|
903 |
| - retVal = custom_func(filterVal, columnVal); |
| 905 | + retVal = custom_func(filterVal, columnVal, aData); |
904 | 906 |
|
905 | 907 | return retVal;
|
906 | 908 | }
|
@@ -1823,10 +1825,11 @@ var yadcf = (function ($) {
|
1823 | 1825 | filter_reset_button_text = "x";
|
1824 | 1826 | }
|
1825 | 1827 |
|
1826 |
| - if (data === undefined) { |
| 1828 | + if (data === undefined || columnObj.append_data_to_table_data === true) { |
1827 | 1829 | columnObj.col_filter_array = undefined;
|
1828 | 1830 | column_data = parseTableColumn(oTable, columnObj);
|
1829 |
| - } else { |
| 1831 | + } |
| 1832 | + if (data !== undefined) { |
1830 | 1833 | for (ii = 0; ii < data.length; ii++) {
|
1831 | 1834 | column_data.push(data[ii]);
|
1832 | 1835 | }
|
@@ -1883,14 +1886,23 @@ var yadcf = (function ($) {
|
1883 | 1886 | if (columnObj.select_type === 'select2' && columnObj.select_type_options.placeholder !== undefined && columnObj.select_type_options.allowClear === true) {
|
1884 | 1887 | options_tmp = "<option value=\"\"></option>";
|
1885 | 1888 | }
|
1886 |
| - |
1887 |
| - if (typeof column_data[0] === 'object') { |
1888 |
| - for (ii = 0; ii < column_data.length; ii++) { |
1889 |
| - options_tmp += "<option value=\"" + column_data[ii].value + "\">" + column_data[ii].label + "</option>"; |
| 1889 | + if (columnObj.append_data_to_table_data !== true) { |
| 1890 | + if (typeof column_data[0] === 'object') { |
| 1891 | + for (ii = 0; ii < column_data.length; ii++) { |
| 1892 | + options_tmp += "<option value=\"" + column_data[ii].value + "\">" + column_data[ii].label + "</option>"; |
| 1893 | + } |
| 1894 | + } else { |
| 1895 | + for (ii = 0; ii < column_data.length; ii++) { |
| 1896 | + options_tmp += "<option value=\"" + column_data[ii] + "\">" + column_data[ii] + "</option>"; |
| 1897 | + } |
1890 | 1898 | }
|
1891 | 1899 | } else {
|
1892 | 1900 | for (ii = 0; ii < column_data.length; ii++) {
|
1893 |
| - options_tmp += "<option value=\"" + column_data[ii] + "\">" + column_data[ii] + "</option>"; |
| 1901 | + if (typeof column_data[ii] === 'object') { |
| 1902 | + options_tmp += "<option value=\"" + column_data[ii].value + "\">" + column_data[ii].label + "</option>"; |
| 1903 | + } else { |
| 1904 | + options_tmp += "<option value=\"" + column_data[ii] + "\">" + column_data[ii] + "</option>"; |
| 1905 | + } |
1894 | 1906 | }
|
1895 | 1907 | }
|
1896 | 1908 | column_data = options_tmp;
|
|
0 commit comments