Skip to content

Commit

Permalink
0.8.5.beta.3 -
Browse files Browse the repository at this point in the history
* New Feature, filters can be placed in the footer or header #85
* New Feature, filter_type: 'custom_func' support state saving #92
  • Loading branch information
vedmack committed Oct 16, 2014
1 parent 24a5cc2 commit caf6b21
Show file tree
Hide file tree
Showing 4 changed files with 2,506 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.8.5 (Still beta)

* New Feature, filters can be placed in the footer or header https://github.com/vedmack/yadcf/issues/85
* New Feature, filter_type: 'custom_func' support state saving https://github.com/vedmack/yadcf/issues/92
* New Feature, Select2 allow use of placeholder with allowClear properties https://github.com/vedmack/yadcf/issues/91
* Bugs fix https://github.com/vedmack/yadcf/issues/89
https://github.com/vedmack/yadcf/issues/68 (sub issue)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Features:
- range of numbers with slider widget - make use of the jQuery UI Slider widget (with some enhancements)
- range of dates - make use of the jQuery UI Datepicker widget (with some enhancements)
- custom function
- Filters can be placed in the header (thead) or in the footer (tfoot) , second argument of yadcf constructor or third argument of init function
- Parsing various types of columns:
- plain text
- plain text with delimiter
Expand Down
86 changes: 75 additions & 11 deletions lab/jquery.dataTables.yadcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Yet Another DataTables Column Filter - (yadcf)
*
* File: jquery.dataTables.yadcf.js
* Version: 0.8.5.beta.2
* Version: 0.8.5.beta.3
*
* Author: Daniel Reznick
* Info: https://github.com/vedmack/yadcf
Expand Down Expand Up @@ -199,8 +199,14 @@
* Range filter value will arrive delimited by -yadcf_delim- , so just split it into an array or something like this: String[] minMax = sSearch_0.split("-yadcf_delim-");
*
*
* -------------
* Filters position
*
*
* -------------
* Filters can be placed in the header (thead) or in the footer (tfoot) , it is defined by the second argument of yadcf constructor
or third argument of init function. Header location is the default position, use 'footer' in order to place the filters in the tfoot position
*/
var yadcf = (function ($) {

Expand Down Expand Up @@ -363,7 +369,9 @@ var yadcf = (function ($) {
}

function doFilterCustomDateFunc(arg, table_selector_jq_friendly, column_number) {
var oTable = oTables[table_selector_jq_friendly];
var oTable = oTables[table_selector_jq_friendly],
yadcfState;

if (arg === "clear" || arg.value === "-1") {
if (arg === "clear") {
$("#yadcf-filter-" + table_selector_jq_friendly + "-" + column_number).val("-1").focus();
Expand All @@ -373,6 +381,27 @@ var yadcf = (function ($) {
$("#yadcf-filter-" + table_selector_jq_friendly + "-" + column_number).addClass("inuse");
}

if (!oTable.fnSettings().oLoadedState) {
oTable.fnSettings().oLoadedState = {};
oTable.fnSettings().oApi._fnSaveState(oTable.fnSettings());
}
if (oTable.fnSettings().oFeatures.bStateSave === true) {
if (oTable.fnSettings().oLoadedState.yadcfState !== undefined && oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly] !== undefined) {
oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly][column_number] =
{
'from' : arg.value
};
} else {
yadcfState = {};
yadcfState[table_selector_jq_friendly] = [];
yadcfState[table_selector_jq_friendly][column_number] = {
'from' : arg.value
};
oTable.fnSettings().oLoadedState.yadcfState = yadcfState;
}
oTable.fnSettings().oApi._fnSaveState(oTable.fnSettings());
}

oTable.fnDraw();
}

Expand Down Expand Up @@ -566,7 +595,7 @@ var yadcf = (function ($) {
function addCustomFunctionFilterCapability(table_selector_jq_friendly, filterId, col_num) {

$.fn.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
function (oSettings, aData, iDataIndex, stateVal) {
var filterVal = document.getElementById(filterId) !== null ? document.getElementById(filterId).value : "",
columnVal = aData[col_num] === "-" ? 0 : aData[col_num],
retVal = false,
Expand Down Expand Up @@ -1174,7 +1203,8 @@ var yadcf = (function ($) {
col_num_visible_iter,
tmpStr,
columnObjKey,
columnObj;
columnObj,
filters_position;


for (columnObjKey in args) {
Expand Down Expand Up @@ -1330,7 +1360,8 @@ var yadcf = (function ($) {
col_num_visible--;
}
}
filter_selector_string = table_selector + " thead th:eq(" + col_num_visible + ")";
filters_position = $(document).data(table_selector + "_filters_position");
filter_selector_string = table_selector + " " + filters_position + " th:eq(" + col_num_visible + ")";
$filter_selector = $(filter_selector_string).find(".yadcf-filter");
} else {
if ($("#" + filter_container_id).length === 0) {
Expand Down Expand Up @@ -1454,6 +1485,17 @@ var yadcf = (function ($) {
$(filter_selector_string).find(".yadcf-filter").after("<input value=\"" + filter_reset_button_text + "\" type=\"button\" " +
"onclick=\"yadcf.stopPropagation(event);yadcf.doFilterCustomDateFunc('clear', '" + table_selector_jq_friendly + "', " + column_number + "); return false;\" class=\"yadcf-filter-reset-button\">");
}

if (oTable.fnSettings().oFeatures.bStateSave === true && oTable.fnSettings().oLoadedState) {
if (oTable.fnSettings().oLoadedState.yadcfState && oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly] && oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly][column_number]) {
tmpStr = oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly][column_number].from;
if (tmpStr === '-1' || tmpStr === undefined) {
$('#yadcf-filter-' + table_selector_jq_friendly + '-' + column_number).val(tmpStr);
} else {
$('#yadcf-filter-' + table_selector_jq_friendly + '-' + column_number).val(tmpStr).addClass("inuse");
}
}
}
if (oTable.fnSettings().oFeatures.bServerSide !== true) {
addCustomFunctionFilterCapability(table_selector_jq_friendly, "yadcf-filter-" + table_selector_jq_friendly + "-" + column_number, column_number);
}
Expand Down Expand Up @@ -1972,14 +2014,21 @@ var yadcf = (function ($) {
return true;
}

function isDOMSource(tableVar) {
if (tableVar.fnSettings().sAjaxSource == null && tableVar.fnSettings().ajax == null) {
return true;
}
return false;
}

function initAndBindTable(oTable, table_selector, index) {

var table_selector_jq_friendly = yadcf.generateTableSelectorJQFriendly(table_selector),
table_selector_tmp;
oTables[table_selector_jq_friendly] = oTable;
oTablesIndex[table_selector_jq_friendly] = index;

if (oTable.fnSettings().sAjaxSource === null && oTable.fnSettings().ajax === null) {
if (isDOMSource(oTable)) {
table_selector_tmp = table_selector;
if (table_selector.indexOf(":eq") !== -1) {
table_selector_tmp = table_selector.substring(0, table_selector.lastIndexOf(":eq"));
Expand Down Expand Up @@ -2035,7 +2084,7 @@ var yadcf = (function ($) {
});
}
//when using DOM source
if (oTable.fnSettings().sAjaxSource === null && oTable.fnSettings().ajax === null) {
if (isDOMSource(oTable)) {
//we need to make sure that the yadcf state will be saved after page reload
oTable.fnSettings().oApi._fnSaveState(oTable.fnSettings());
//redraw the table in order to apply the filters
Expand All @@ -2044,7 +2093,14 @@ var yadcf = (function ($) {
}
}

$.fn.yadcf = function (options_arg) {
$.fn.yadcf = function (options_arg, filters_position) {

if (filters_position === undefined || filters_position === 'header') {
filters_position = 'thead';
} else {
filters_position = 'tfoot';
}
$(document).data(this.selector + "_filters_position", filters_position);

if ($(this.selector).length === 1) {
setOptions(this.selector, options_arg);
Expand All @@ -2063,10 +2119,18 @@ var yadcf = (function ($) {
return this;
};

function init(oTable, options_arg) {
function init(oTable, options_arg, filters_position) {
var instance = oTable.settings()[0].oInstance,
i = 0,
selector;

if (filters_position === undefined || filters_position === 'header') {
filters_position = 'thead';
} else {
filters_position = 'tfoot';
}
$(document).data(instance.selector + "_filters_position", filters_position);

if ($(instance.selector).length === 1) {
setOptions(instance.selector, options_arg);
initAndBindTable(instance, instance.selector, 0);
Expand Down Expand Up @@ -2154,7 +2218,7 @@ var yadcf = (function ($) {
table_arg = table_arg.settings()[0].oInstance;
}
table_selector_jq_friendly = yadcf.generateTableSelectorJQFriendly(table_arg.selector);
if ((table_arg.fnSettings().sAjaxSource === null && (table_arg.fnSettings().ajax === null || table_arg.fnSettings().ajax === undefined)) || ajaxSource === true) {
if (isDOMSource(table_arg) || ajaxSource === true) {
for (j = 0; j < col_filter_arr.length; j++) {
column_number = col_filter_arr[j][0];
optionsObj = getOptions(table_arg.selector)[column_number];
Expand Down
Loading

0 comments on commit caf6b21

Please sign in to comment.