Skip to content

Commit 55812d4

Browse files
committed
append_data_to_table_data
filter in column based on data in other column/s #178 #179
1 parent 6b7f3ee commit 55812d4

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

beta/jquery.dataTables.yadcf.js

+29-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Yet Another DataTables Column Filter - (yadcf)
55
*
66
* File: jquery.dataTables.yadcf.js
7-
* Version: 0.8.8.beta.12
7+
* Version: 0.8.8.beta.13
88
*
99
* Author: Daniel Reznick
1010
* Info: https://github.com/vedmack/yadcf
@@ -41,17 +41,23 @@
4141
Required: true (when filter_type is custom_func / multi_select_custom_func)
4242
Type: function
4343
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
4646
Note: When using multi_select_custom_func as filter_type filterVal will hold an array of selected values from the multi select element
4747
4848
* data
49-
Required: false / true (when filter_type is custom_func / multi_select_custom_func)
49+
Required: false
5050
Type: Array (of string or objects)
5151
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
5252
array of objects [{value: 'Some Data 1', label: 'One'}, {value: 'Some Data 3', label: 'Three'}] (supported in select / multi_select filters)
5353
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+
5561
* column_data_type
5662
Required: false
5763
Type: String
@@ -412,10 +418,6 @@ var yadcf = (function ($) {
412418
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...\")');
413419
return;
414420
}
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-
}
419421
}
420422
col_num_as_int = +options_arg[i].column_number;
421423
if (isNaN(col_num_as_int)) {
@@ -900,7 +902,7 @@ var yadcf = (function ($) {
900902

901903
custom_func = getOptions(settingsDt.oInstance.selector)[col_num].custom_func;
902904

903-
retVal = custom_func(filterVal, columnVal);
905+
retVal = custom_func(filterVal, columnVal, aData);
904906

905907
return retVal;
906908
}
@@ -1823,10 +1825,11 @@ var yadcf = (function ($) {
18231825
filter_reset_button_text = "x";
18241826
}
18251827

1826-
if (data === undefined) {
1828+
if (data === undefined || columnObj.append_data_to_table_data === true) {
18271829
columnObj.col_filter_array = undefined;
18281830
column_data = parseTableColumn(oTable, columnObj);
1829-
} else {
1831+
}
1832+
if (data !== undefined) {
18301833
for (ii = 0; ii < data.length; ii++) {
18311834
column_data.push(data[ii]);
18321835
}
@@ -1883,14 +1886,23 @@ var yadcf = (function ($) {
18831886
if (columnObj.select_type === 'select2' && columnObj.select_type_options.placeholder !== undefined && columnObj.select_type_options.allowClear === true) {
18841887
options_tmp = "<option value=\"\"></option>";
18851888
}
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+
}
18901898
}
18911899
} else {
18921900
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+
}
18941906
}
18951907
}
18961908
column_data = options_tmp;

0 commit comments

Comments
 (0)