/pack-rat/003_pack_rat/pack-rat/node_modules/bootstrap-table/docs/dist/extensions/filter-control/bootstrap-table-filter-control.js |
@@ -0,0 +1,697 @@ |
/** |
* @author: Dennis Hernández |
* @webSite: http://djhvscf.github.io/Blog |
* @version: v2.1.1 |
*/ |
|
(function ($) { |
|
'use strict'; |
|
var sprintf = $.fn.bootstrapTable.utils.sprintf, |
objectKeys = $.fn.bootstrapTable.utils.objectKeys; |
|
var getOptionsFromSelectControl = function (selectControl) { |
return selectControl.get(selectControl.length - 1).options; |
}; |
|
var hideUnusedSelectOptions = function (selectControl, uniqueValues) { |
var options = getOptionsFromSelectControl(selectControl); |
|
for (var i = 0; i < options.length; i++) { |
if (options[i].value !== "") { |
if (!uniqueValues.hasOwnProperty(options[i].value)) { |
selectControl.find(sprintf("option[value='%s']", options[i].value)).hide(); |
} else { |
selectControl.find(sprintf("option[value='%s']", options[i].value)).show(); |
} |
} |
} |
}; |
|
var addOptionToSelectControl = function (selectControl, value, text) { |
value = $.trim(value); |
selectControl = $(selectControl.get(selectControl.length - 1)); |
if (!existOptionInSelectControl(selectControl, value)) { |
selectControl.append($("<option></option>") |
.attr("value", value) |
.text($('<div />').html(text).text())); |
} |
}; |
|
var sortSelectControl = function (selectControl) { |
var $opts = selectControl.find('option:gt(0)'); |
$opts.sort(function (a, b) { |
a = $(a).text().toLowerCase(); |
b = $(b).text().toLowerCase(); |
if ($.isNumeric(a) && $.isNumeric(b)) { |
// Convert numerical values from string to float. |
a = parseFloat(a); |
b = parseFloat(b); |
} |
return a > b ? 1 : a < b ? -1 : 0; |
}); |
|
selectControl.find('option:gt(0)').remove(); |
selectControl.append($opts); |
}; |
|
var existOptionInSelectControl = function (selectControl, value) { |
var options = getOptionsFromSelectControl(selectControl); |
for (var i = 0; i < options.length; i++) { |
if (options[i].value === value.toString()) { |
//The value is not valid to add |
return true; |
} |
} |
|
//If we get here, the value is valid to add |
return false; |
}; |
|
var fixHeaderCSS = function (that) { |
that.$tableHeader.css('height', '77px'); |
}; |
|
var getCurrentHeader = function (that) { |
var header = that.$header; |
if (that.options.height) { |
header = that.$tableHeader; |
} |
|
return header; |
}; |
|
var getCurrentSearchControls = function (that) { |
var searchControls = 'select, input'; |
if (that.options.height) { |
searchControls = 'table select, table input'; |
} |
|
return searchControls; |
}; |
|
var getCursorPosition = function(el) { |
if ($.fn.bootstrapTable.utils.isIEBrowser()) { |
if ($(el).is('input')) { |
var pos = 0; |
if ('selectionStart' in el) { |
pos = el.selectionStart; |
} else if ('selection' in document) { |
el.focus(); |
var Sel = document.selection.createRange(); |
var SelLength = document.selection.createRange().text.length; |
Sel.moveStart('character', -el.value.length); |
pos = Sel.text.length - SelLength; |
} |
return pos; |
} else { |
return -1; |
} |
} else { |
return -1; |
} |
}; |
|
var setCursorPosition = function (el, index) { |
if ($.fn.bootstrapTable.utils.isIEBrowser()) { |
if(el.setSelectionRange !== undefined) { |
el.setSelectionRange(index, index); |
} else { |
$(el).val(el.value); |
} |
} |
}; |
|
var copyValues = function (that) { |
var header = getCurrentHeader(that), |
searchControls = getCurrentSearchControls(that); |
|
that.options.valuesFilterControl = []; |
|
header.find(searchControls).each(function () { |
that.options.valuesFilterControl.push( |
{ |
field: $(this).closest('[data-field]').data('field'), |
value: $(this).val(), |
position: getCursorPosition($(this).get(0)) |
}); |
}); |
}; |
|
var setValues = function(that) { |
var field = null, |
result = [], |
header = getCurrentHeader(that), |
searchControls = getCurrentSearchControls(that); |
|
if (that.options.valuesFilterControl.length > 0) { |
header.find(searchControls).each(function (index, ele) { |
field = $(this).closest('[data-field]').data('field'); |
result = $.grep(that.options.valuesFilterControl, function (valueObj) { |
return valueObj.field === field; |
}); |
|
if (result.length > 0) { |
$(this).val(result[0].value); |
setCursorPosition($(this).get(0), result[0].position); |
} |
}); |
} |
}; |
|
var collectBootstrapCookies = function cookiesRegex() { |
var cookies = [], |
foundCookies = document.cookie.match(/(?:bs.table.)(\w*)/g); |
|
if (foundCookies) { |
$.each(foundCookies, function (i, cookie) { |
if (/./.test(cookie)) { |
cookie = cookie.split(".").pop(); |
} |
|
if ($.inArray(cookie, cookies) === -1) { |
cookies.push(cookie); |
} |
}); |
return cookies; |
} |
}; |
|
var initFilterSelectControls = function (that) { |
var data = that.data, |
itemsPerPage = that.pageTo < that.options.data.length ? that.options.data.length : that.pageTo, |
|
isColumnSearchableViaSelect = function (column) { |
return column.filterControl && column.filterControl.toLowerCase() === 'select' && column.searchable; |
}, |
|
isFilterDataNotGiven = function (column) { |
return column.filterData === undefined || column.filterData.toLowerCase() === 'column'; |
}, |
|
hasSelectControlElement = function (selectControl) { |
return selectControl && selectControl.length > 0; |
}; |
|
var z = that.options.pagination ? |
(that.options.sidePagination === 'server' ? that.pageTo : that.options.totalRows) : |
that.pageTo; |
|
$.each(that.header.fields, function (j, field) { |
var column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, field)], |
selectControl = $('.bootstrap-table-filter-control-' + escapeID(column.field)); |
|
if (isColumnSearchableViaSelect(column) && isFilterDataNotGiven(column) && hasSelectControlElement(selectControl)) { |
if (selectControl.get(selectControl.length - 1).options.length === 0) { |
//Added the default option |
addOptionToSelectControl(selectControl, '', ''); |
} |
|
var uniqueValues = {}; |
for (var i = 0; i < z; i++) { |
//Added a new value |
var fieldValue = data[i][field], |
formattedValue = $.fn.bootstrapTable.utils.calculateObjectValue(that.header, that.header.formatters[j], [fieldValue, data[i], i], fieldValue); |
|
uniqueValues[formattedValue] = fieldValue; |
} |
|
for (var key in uniqueValues) { |
addOptionToSelectControl(selectControl, uniqueValues[key], key); |
} |
|
sortSelectControl(selectControl); |
|
if (that.options.hideUnusedSelectOptions) { |
hideUnusedSelectOptions(selectControl, uniqueValues); |
} |
} |
}); |
}; |
|
var escapeID = function(id) { |
return String(id).replace( /(:|\.|\[|\]|,)/g, "\\$1" ); |
}; |
|
var createControls = function (that, header) { |
var addedFilterControl = false, |
isVisible, |
html, |
timeoutId = 0; |
|
$.each(that.columns, function (i, column) { |
isVisible = 'hidden'; |
html = []; |
|
if (!column.visible) { |
return; |
} |
|
if (!column.filterControl) { |
html.push('<div class="no-filter-control"></div>'); |
} else { |
html.push('<div class="filter-control">'); |
|
var nameControl = column.filterControl.toLowerCase(); |
if (column.searchable && that.options.filterTemplate[nameControl]) { |
addedFilterControl = true; |
isVisible = 'visible'; |
html.push(that.options.filterTemplate[nameControl](that, column.field, isVisible, column.filterControlPlaceholder)); |
} |
} |
|
$.each(header.children().children(), function (i, tr) { |
tr = $(tr); |
if (tr.data('field') === column.field) { |
tr.find('.fht-cell').append(html.join('')); |
return false; |
} |
}); |
|
if (column.filterData !== undefined && column.filterData.toLowerCase() !== 'column') { |
var filterDataType = getFilterDataMethod(filterDataMethods, column.filterData.substring(0, column.filterData.indexOf(':'))); |
var filterDataSource, selectControl; |
|
if (filterDataType !== null) { |
filterDataSource = column.filterData.substring(column.filterData.indexOf(':') + 1, column.filterData.length); |
selectControl = $('.bootstrap-table-filter-control-' + escapeID(column.field)); |
|
addOptionToSelectControl(selectControl, '', ''); |
filterDataType(filterDataSource, selectControl); |
} else { |
throw new SyntaxError('Error. You should use any of these allowed filter data methods: var, json, url.' + ' Use like this: var: {key: "value"}'); |
} |
|
var variableValues, key; |
switch (filterDataType) { |
case 'url': |
$.ajax({ |
url: filterDataSource, |
dataType: 'json', |
success: function (data) { |
for (var key in data) { |
addOptionToSelectControl(selectControl, key, data[key]); |
} |
sortSelectControl(selectControl); |
} |
}); |
break; |
case 'var': |
variableValues = window[filterDataSource]; |
for (key in variableValues) { |
addOptionToSelectControl(selectControl, key, variableValues[key]); |
} |
sortSelectControl(selectControl); |
break; |
case 'jso': |
variableValues = JSON.parse(filterDataSource); |
for (key in variableValues) { |
addOptionToSelectControl(selectControl, key, variableValues[key]); |
} |
sortSelectControl(selectControl); |
break; |
} |
} |
}); |
|
if (addedFilterControl) { |
header.off('keyup', 'input').on('keyup', 'input', function (event) { |
clearTimeout(timeoutId); |
timeoutId = setTimeout(function () { |
that.onColumnSearch(event); |
}, that.options.searchTimeOut); |
}); |
|
header.off('change', 'select').on('change', 'select', function (event) { |
clearTimeout(timeoutId); |
timeoutId = setTimeout(function () { |
that.onColumnSearch(event); |
}, that.options.searchTimeOut); |
}); |
|
header.off('mouseup', 'input').on('mouseup', 'input', function (event) { |
var $input = $(this), |
oldValue = $input.val(); |
|
if (oldValue === "") { |
return; |
} |
|
setTimeout(function(){ |
var newValue = $input.val(); |
|
if (newValue === "") { |
clearTimeout(timeoutId); |
timeoutId = setTimeout(function () { |
that.onColumnSearch(event); |
}, that.options.searchTimeOut); |
} |
}, 1); |
}); |
|
if (header.find('.date-filter-control').length > 0) { |
$.each(that.columns, function (i, column) { |
if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'datepicker') { |
header.find('.date-filter-control.bootstrap-table-filter-control-' + column.field).datepicker(column.filterDatepickerOptions) |
.on('changeDate', function (e) { |
$(sprintf(".%s", e.currentTarget.classList.toString().split(" ").join("."))).val(e.currentTarget.value); |
//Fired the keyup event |
$(e.currentTarget).keyup(); |
}); |
} |
}); |
} |
} else { |
header.find('.filterControl').hide(); |
} |
}; |
|
var getDirectionOfSelectOptions = function (alignment) { |
alignment = alignment === undefined ? 'left' : alignment.toLowerCase(); |
|
switch (alignment) { |
case 'left': |
return 'ltr'; |
case 'right': |
return 'rtl'; |
case 'auto': |
return 'auto'; |
default: |
return 'ltr'; |
} |
}; |
|
var filterDataMethods = |
{ |
'var': function (filterDataSource, selectControl) { |
var variableValues = window[filterDataSource]; |
for (var key in variableValues) { |
addOptionToSelectControl(selectControl, key, variableValues[key]); |
} |
sortSelectControl(selectControl); |
}, |
'url': function (filterDataSource, selectControl) { |
$.ajax({ |
url: filterDataSource, |
dataType: 'json', |
success: function (data) { |
for (var key in data) { |
addOptionToSelectControl(selectControl, key, data[key]); |
} |
sortSelectControl(selectControl); |
} |
}); |
}, |
'json':function (filterDataSource, selectControl) { |
var variableValues = JSON.parse(filterDataSource); |
for (var key in variableValues) { |
addOptionToSelectControl(selectControl, key, variableValues[key]); |
} |
sortSelectControl(selectControl); |
} |
}; |
|
var getFilterDataMethod = function (objFilterDataMethod, searchTerm) { |
var keys = Object.keys(objFilterDataMethod); |
for (var i = 0; i < keys.length; i++) { |
if (keys[i] === searchTerm) { |
return objFilterDataMethod[searchTerm]; |
} |
} |
return null; |
}; |
|
$.extend($.fn.bootstrapTable.defaults, { |
filterControl: false, |
onColumnSearch: function (field, text) { |
return false; |
}, |
filterShowClear: false, |
alignmentSelectControlOptions: undefined, |
filterTemplate: { |
input: function (that, field, isVisible, placeholder) { |
return sprintf('<input type="text" class="form-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s" placeholder="%s">', field, isVisible, placeholder); |
}, |
select: function (that, field, isVisible) { |
return sprintf('<select class="form-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s" dir="%s"></select>', |
field, isVisible, getDirectionOfSelectOptions(that.options.alignmentSelectControlOptions)); |
}, |
datepicker: function (that, field, isVisible) { |
return sprintf('<input type="text" class="form-control date-filter-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s">', field, isVisible); |
} |
}, |
//internal variables |
valuesFilterControl: [] |
}); |
|
$.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, { |
filterControl: undefined, |
filterData: undefined, |
filterDatepickerOptions: undefined, |
filterStrictSearch: false, |
filterStartsWithSearch: false, |
filterControlPlaceholder: "" |
}); |
|
$.extend($.fn.bootstrapTable.Constructor.EVENTS, { |
'column-search.bs.table': 'onColumnSearch' |
}); |
|
$.extend($.fn.bootstrapTable.defaults.icons, { |
clear: 'glyphicon-trash icon-clear' |
}); |
|
$.extend($.fn.bootstrapTable.locales, { |
formatClearFilters: function () { |
return 'Clear Filters'; |
} |
}); |
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales); |
|
var BootstrapTable = $.fn.bootstrapTable.Constructor, |
_init = BootstrapTable.prototype.init, |
_initToolbar = BootstrapTable.prototype.initToolbar, |
_initHeader = BootstrapTable.prototype.initHeader, |
_initBody = BootstrapTable.prototype.initBody, |
_initSearch = BootstrapTable.prototype.initSearch; |
|
BootstrapTable.prototype.init = function () { |
//Make sure that the filterControl option is set |
if (this.options.filterControl) { |
var that = this; |
|
// Compatibility: IE < 9 and old browsers |
if (!Object.keys) { |
objectKeys(); |
} |
|
//Make sure that the internal variables are set correctly |
this.options.valuesFilterControl = []; |
|
this.$el.on('reset-view.bs.table', function () { |
//Create controls on $tableHeader if the height is set |
if (!that.options.height) { |
return; |
} |
|
//Avoid recreate the controls |
if (that.$tableHeader.find('select').length > 0 || that.$tableHeader.find('input').length > 0) { |
return; |
} |
|
createControls(that, that.$tableHeader); |
}).on('post-header.bs.table', function () { |
setValues(that); |
}).on('post-body.bs.table', function () { |
if (that.options.height) { |
fixHeaderCSS(that); |
} |
}).on('column-switch.bs.table', function() { |
setValues(that); |
}); |
} |
_init.apply(this, Array.prototype.slice.apply(arguments)); |
}; |
|
BootstrapTable.prototype.initToolbar = function () { |
this.showToolbar = this.options.filterControl && this.options.filterShowClear; |
|
_initToolbar.apply(this, Array.prototype.slice.apply(arguments)); |
|
if (this.options.filterControl && this.options.filterShowClear) { |
var $btnGroup = this.$toolbar.find('>.btn-group'), |
$btnClear = $btnGroup.find('.filter-show-clear'); |
|
if (!$btnClear.length) { |
$btnClear = $([ |
'<button class="btn btn-default filter-show-clear" ', |
sprintf('type="button" title="%s">', this.options.formatClearFilters()), |
sprintf('<i class="%s %s"></i> ', this.options.iconsPrefix, this.options.icons.clear), |
'</button>' |
].join('')).appendTo($btnGroup); |
|
$btnClear.off('click').on('click', $.proxy(this.clearFilterControl, this)); |
} |
} |
}; |
|
BootstrapTable.prototype.initHeader = function () { |
_initHeader.apply(this, Array.prototype.slice.apply(arguments)); |
|
if (!this.options.filterControl) { |
return; |
} |
createControls(this, this.$header); |
}; |
|
BootstrapTable.prototype.initBody = function () { |
_initBody.apply(this, Array.prototype.slice.apply(arguments)); |
|
initFilterSelectControls(this); |
}; |
|
BootstrapTable.prototype.initSearch = function () { |
_initSearch.apply(this, Array.prototype.slice.apply(arguments)); |
|
if (this.options.sidePagination === 'server') { |
return; |
} |
|
var that = this; |
var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial; |
|
//Check partial column filter |
this.data = fp ? $.grep(this.data, function (item, i) { |
for (var key in fp) { |
var thisColumn = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, key)]; |
var fval = fp[key].toLowerCase(); |
var value = item[key]; |
|
// Fix #142: search use formated data |
if (thisColumn && thisColumn.searchFormatter) { |
value = $.fn.bootstrapTable.utils.calculateObjectValue(that.header, |
that.header.formatters[$.inArray(key, that.header.fields)], |
[value, item, i], value); |
} |
|
if (thisColumn.filterStrictSearch) { |
if (!($.inArray(key, that.header.fields) !== -1 && |
(typeof value === 'string' || typeof value === 'number') && |
value.toString().toLowerCase() === fval.toString().toLowerCase())) { |
return false; |
} |
} else if (thisColumn.filterStartsWithSearch) { |
if (!($.inArray(key, that.header.fields) !== -1 && |
(typeof value === 'string' || typeof value === 'number') && |
(value + '').toLowerCase().indexOf(fval) === 0)) { |
return false; |
} |
} else { |
if (!($.inArray(key, that.header.fields) !== -1 && |
(typeof value === 'string' || typeof value === 'number') && |
(value + '').toLowerCase().indexOf(fval) !== -1)) { |
return false; |
} |
} |
} |
return true; |
}) : this.data; |
}; |
|
BootstrapTable.prototype.initColumnSearch = function(filterColumnsDefaults) { |
copyValues(this); |
|
if (filterColumnsDefaults) { |
this.filterColumnsPartial = filterColumnsDefaults; |
this.updatePagination(); |
|
for (var filter in filterColumnsDefaults) { |
this.trigger('column-search', filter, filterColumnsDefaults[filter]); |
} |
} |
}; |
|
BootstrapTable.prototype.onColumnSearch = function (event) { |
if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) { |
return; |
} |
|
copyValues(this); |
var text = $.trim($(event.currentTarget).val()); |
var $field = $(event.currentTarget).closest('[data-field]').data('field'); |
|
if ($.isEmptyObject(this.filterColumnsPartial)) { |
this.filterColumnsPartial = {}; |
} |
if (text) { |
this.filterColumnsPartial[$field] = text; |
} else { |
delete this.filterColumnsPartial[$field]; |
} |
|
// if the searchText is the same as the previously selected column value, |
// bootstrapTable will not try searching again (even though the selected column |
// may be different from the previous search). As a work around |
// we're manually appending some text to bootrap's searchText field |
// to guarantee that it will perform a search again when we call this.onSearch(event) |
this.searchText += "randomText"; |
|
this.options.pageNumber = 1; |
this.onSearch(event); |
this.trigger('column-search', $field, text); |
}; |
|
BootstrapTable.prototype.clearFilterControl = function () { |
if (this.options.filterControl && this.options.filterShowClear) { |
var that = this, |
cookies = collectBootstrapCookies(), |
header = getCurrentHeader(that), |
table = header.closest('table'), |
controls = header.find(getCurrentSearchControls(that)), |
search = that.$toolbar.find('.search input'), |
timeoutId = 0; |
|
$.each(that.options.valuesFilterControl, function (i, item) { |
item.value = ''; |
}); |
|
setValues(that); |
|
// Clear each type of filter if it exists. |
// Requires the body to reload each time a type of filter is found because we never know |
// which ones are going to be present. |
if (controls.length > 0) { |
this.filterColumnsPartial = {}; |
$(controls[0]).trigger(controls[0].tagName === 'INPUT' ? 'keyup' : 'change'); |
} else { |
return; |
} |
|
if (search.length > 0) { |
that.resetSearch(); |
} |
|
// use the default sort order if it exists. do nothing if it does not |
if (that.options.sortName !== table.data('sortName') || that.options.sortOrder !== table.data('sortOrder')) { |
var sorter = header.find(sprintf('[data-field="%s"]', $(controls[0]).closest('table').data('sortName'))); |
if (sorter.length > 0) { |
that.onSort(table.data('sortName'), table.data('sortName')); |
$(sorter).find('.sortable').trigger('click'); |
} |
} |
|
// clear cookies once the filters are clean |
clearTimeout(timeoutId); |
timeoutId = setTimeout(function () { |
if (cookies && cookies.length > 0) { |
$.each(cookies, function (i, item) { |
if (that.deleteCookie !== undefined) { |
that.deleteCookie(item); |
} |
}); |
} |
}, that.options.searchTimeOut); |
} |
}; |
})(jQuery); |
/pack-rat/003_pack_rat/pack-rat/node_modules/bootstrap-table/docs/dist/extensions/filter-control/bootstrap-table-filter-control.min.js |
@@ -0,0 +1,7 @@ |
/* |
* bootstrap-table - v1.11.1 - 2017-02-22 |
* https://github.com/wenzhixin/bootstrap-table |
* Copyright (c) 2017 zhixin wen |
* Licensed MIT License |
*/ |
!function(a){"use strict";var b=a.fn.bootstrapTable.utils.sprintf,c=a.fn.bootstrapTable.utils.objectKeys,d=function(a){return a.get(a.length-1).options},e=function(a,c){for(var e=d(a),f=0;f<e.length;f++)""!==e[f].value&&(c.hasOwnProperty(e[f].value)?a.find(b("option[value='%s']",e[f].value)).show():a.find(b("option[value='%s']",e[f].value)).hide())},f=function(b,c,d){c=a.trim(c),b=a(b.get(b.length-1)),h(b,c)||b.append(a("<option></option>").attr("value",c).text(a("<div />").html(d).text()))},g=function(b){var c=b.find("option:gt(0)");c.sort(function(b,c){return b=a(b).text().toLowerCase(),c=a(c).text().toLowerCase(),a.isNumeric(b)&&a.isNumeric(c)&&(b=parseFloat(b),c=parseFloat(c)),b>c?1:c>b?-1:0}),b.find("option:gt(0)").remove(),b.append(c)},h=function(a,b){for(var c=d(a),e=0;e<c.length;e++)if(c[e].value===b.toString())return!0;return!1},i=function(a){a.$tableHeader.css("height","77px")},j=function(a){var b=a.$header;return a.options.height&&(b=a.$tableHeader),b},k=function(a){var b="select, input";return a.options.height&&(b="table select, table input"),b},l=function(b){if(a.fn.bootstrapTable.utils.isIEBrowser()){if(a(b).is("input")){var c=0;if("selectionStart"in b)c=b.selectionStart;else if("selection"in document){b.focus();var d=document.selection.createRange(),e=document.selection.createRange().text.length;d.moveStart("character",-b.value.length),c=d.text.length-e}return c}return-1}return-1},m=function(b,c){a.fn.bootstrapTable.utils.isIEBrowser()&&(void 0!==b.setSelectionRange?b.setSelectionRange(c,c):a(b).val(b.value))},n=function(b){var c=j(b),d=k(b);b.options.valuesFilterControl=[],c.find(d).each(function(){b.options.valuesFilterControl.push({field:a(this).closest("[data-field]").data("field"),value:a(this).val(),position:l(a(this).get(0))})})},o=function(b){var c=null,d=[],e=j(b),f=k(b);b.options.valuesFilterControl.length>0&&e.find(f).each(function(){c=a(this).closest("[data-field]").data("field"),d=a.grep(b.options.valuesFilterControl,function(a){return a.field===c}),d.length>0&&(a(this).val(d[0].value),m(a(this).get(0),d[0].position))})},p=function(){var b=[],c=document.cookie.match(/(?:bs.table.)(\w*)/g);return c?(a.each(c,function(c,d){/./.test(d)&&(d=d.split(".").pop()),-1===a.inArray(d,b)&&b.push(d)}),b):void 0},q=function(b){var c=b.data,d=(b.pageTo<b.options.data.length?b.options.data.length:b.pageTo,function(a){return a.filterControl&&"select"===a.filterControl.toLowerCase()&&a.searchable}),h=function(a){return void 0===a.filterData||"column"===a.filterData.toLowerCase()},i=function(a){return a&&a.length>0},j=b.options.pagination?"server"===b.options.sidePagination?b.pageTo:b.options.totalRows:b.pageTo;a.each(b.header.fields,function(k,l){var m=b.columns[a.fn.bootstrapTable.utils.getFieldIndex(b.columns,l)],n=a(".bootstrap-table-filter-control-"+r(m.field));if(d(m)&&h(m)&&i(n)){0===n.get(n.length-1).options.length&&f(n,"","");for(var o={},p=0;j>p;p++){var q=c[p][l],s=a.fn.bootstrapTable.utils.calculateObjectValue(b.header,b.header.formatters[k],[q,c[p],p],q);o[s]=q}for(var t in o)f(n,o[t],t);g(n),b.options.hideUnusedSelectOptions&&e(n,o)}})},r=function(a){return String(a).replace(/(:|\.|\[|\]|,)/g,"\\$1")},s=function(c,d){var e,h,i=!1,j=0;a.each(c.columns,function(b,j){if(e="hidden",h=[],j.visible){if(j.filterControl){h.push('<div class="filter-control">');var k=j.filterControl.toLowerCase();j.searchable&&c.options.filterTemplate[k]&&(i=!0,e="visible",h.push(c.options.filterTemplate[k](c,j.field,e,j.filterControlPlaceholder)))}else h.push('<div class="no-filter-control"></div>');if(a.each(d.children().children(),function(b,c){return c=a(c),c.data("field")===j.field?(c.find(".fht-cell").append(h.join("")),!1):void 0}),void 0!==j.filterData&&"column"!==j.filterData.toLowerCase()){var l,m,n=v(u,j.filterData.substring(0,j.filterData.indexOf(":")));if(null===n)throw new SyntaxError('Error. You should use any of these allowed filter data methods: var, json, url. Use like this: var: {key: "value"}');l=j.filterData.substring(j.filterData.indexOf(":")+1,j.filterData.length),m=a(".bootstrap-table-filter-control-"+r(j.field)),f(m,"",""),n(l,m);var o,p;switch(n){case"url":a.ajax({url:l,dataType:"json",success:function(a){for(var b in a)f(m,b,a[b]);g(m)}});break;case"var":o=window[l];for(p in o)f(m,p,o[p]);g(m);break;case"jso":o=JSON.parse(l);for(p in o)f(m,p,o[p]);g(m)}}}}),i?(d.off("keyup","input").on("keyup","input",function(a){clearTimeout(j),j=setTimeout(function(){c.onColumnSearch(a)},c.options.searchTimeOut)}),d.off("change","select").on("change","select",function(a){clearTimeout(j),j=setTimeout(function(){c.onColumnSearch(a)},c.options.searchTimeOut)}),d.off("mouseup","input").on("mouseup","input",function(b){var d=a(this),e=d.val();""!==e&&setTimeout(function(){var a=d.val();""===a&&(clearTimeout(j),j=setTimeout(function(){c.onColumnSearch(b)},c.options.searchTimeOut))},1)}),d.find(".date-filter-control").length>0&&a.each(c.columns,function(c,e){void 0!==e.filterControl&&"datepicker"===e.filterControl.toLowerCase()&&d.find(".date-filter-control.bootstrap-table-filter-control-"+e.field).datepicker(e.filterDatepickerOptions).on("changeDate",function(c){a(b(".%s",c.currentTarget.classList.toString().split(" ").join("."))).val(c.currentTarget.value),a(c.currentTarget).keyup()})})):d.find(".filterControl").hide()},t=function(a){switch(a=void 0===a?"left":a.toLowerCase()){case"left":return"ltr";case"right":return"rtl";case"auto":return"auto";default:return"ltr"}},u={"var":function(a,b){var c=window[a];for(var d in c)f(b,d,c[d]);g(b)},url:function(b,c){a.ajax({url:b,dataType:"json",success:function(a){for(var b in a)f(c,b,a[b]);g(c)}})},json:function(a,b){var c=JSON.parse(a);for(var d in c)f(b,d,c[d]);g(b)}},v=function(a,b){for(var c=Object.keys(a),d=0;d<c.length;d++)if(c[d]===b)return a[b];return null};a.extend(a.fn.bootstrapTable.defaults,{filterControl:!1,onColumnSearch:function(){return!1},filterShowClear:!1,alignmentSelectControlOptions:void 0,filterTemplate:{input:function(a,c,d,e){return b('<input type="text" class="form-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s" placeholder="%s">',c,d,e)},select:function(a,c,d){return b('<select class="form-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s" dir="%s"></select>',c,d,t(a.options.alignmentSelectControlOptions))},datepicker:function(a,c,d){return b('<input type="text" class="form-control date-filter-control bootstrap-table-filter-control-%s" style="width: 100%; visibility: %s">',c,d)}},valuesFilterControl:[]}),a.extend(a.fn.bootstrapTable.COLUMN_DEFAULTS,{filterControl:void 0,filterData:void 0,filterDatepickerOptions:void 0,filterStrictSearch:!1,filterStartsWithSearch:!1,filterControlPlaceholder:""}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"column-search.bs.table":"onColumnSearch"}),a.extend(a.fn.bootstrapTable.defaults.icons,{clear:"glyphicon-trash icon-clear"}),a.extend(a.fn.bootstrapTable.locales,{formatClearFilters:function(){return"Clear Filters"}}),a.extend(a.fn.bootstrapTable.defaults,a.fn.bootstrapTable.locales);var w=a.fn.bootstrapTable.Constructor,x=w.prototype.init,y=w.prototype.initToolbar,z=w.prototype.initHeader,A=w.prototype.initBody,B=w.prototype.initSearch;w.prototype.init=function(){if(this.options.filterControl){var a=this;Object.keys||c(),this.options.valuesFilterControl=[],this.$el.on("reset-view.bs.table",function(){a.options.height&&(a.$tableHeader.find("select").length>0||a.$tableHeader.find("input").length>0||s(a,a.$tableHeader))}).on("post-header.bs.table",function(){o(a)}).on("post-body.bs.table",function(){a.options.height&&i(a)}).on("column-switch.bs.table",function(){o(a)})}x.apply(this,Array.prototype.slice.apply(arguments))},w.prototype.initToolbar=function(){if(this.showToolbar=this.options.filterControl&&this.options.filterShowClear,y.apply(this,Array.prototype.slice.apply(arguments)),this.options.filterControl&&this.options.filterShowClear){var c=this.$toolbar.find(">.btn-group"),d=c.find(".filter-show-clear");d.length||(d=a(['<button class="btn btn-default filter-show-clear" ',b('type="button" title="%s">',this.options.formatClearFilters()),b('<i class="%s %s"></i> ',this.options.iconsPrefix,this.options.icons.clear),"</button>"].join("")).appendTo(c),d.off("click").on("click",a.proxy(this.clearFilterControl,this)))}},w.prototype.initHeader=function(){z.apply(this,Array.prototype.slice.apply(arguments)),this.options.filterControl&&s(this,this.$header)},w.prototype.initBody=function(){A.apply(this,Array.prototype.slice.apply(arguments)),q(this)},w.prototype.initSearch=function(){if(B.apply(this,Array.prototype.slice.apply(arguments)),"server"!==this.options.sidePagination){var b=this,c=a.isEmptyObject(this.filterColumnsPartial)?null:this.filterColumnsPartial;this.data=c?a.grep(this.data,function(d,e){for(var f in c){var g=b.columns[a.fn.bootstrapTable.utils.getFieldIndex(b.columns,f)],h=c[f].toLowerCase(),i=d[f];if(g&&g.searchFormatter&&(i=a.fn.bootstrapTable.utils.calculateObjectValue(b.header,b.header.formatters[a.inArray(f,b.header.fields)],[i,d,e],i)),g.filterStrictSearch){if(-1===a.inArray(f,b.header.fields)||"string"!=typeof i&&"number"!=typeof i||i.toString().toLowerCase()!==h.toString().toLowerCase())return!1}else if(g.filterStartsWithSearch){if(-1===a.inArray(f,b.header.fields)||"string"!=typeof i&&"number"!=typeof i||0!==(i+"").toLowerCase().indexOf(h))return!1}else if(-1===a.inArray(f,b.header.fields)||"string"!=typeof i&&"number"!=typeof i||-1===(i+"").toLowerCase().indexOf(h))return!1}return!0}):this.data}},w.prototype.initColumnSearch=function(a){if(n(this),a){this.filterColumnsPartial=a,this.updatePagination();for(var b in a)this.trigger("column-search",b,a[b])}},w.prototype.onColumnSearch=function(b){if(!(a.inArray(b.keyCode,[37,38,39,40])>-1)){n(this);var c=a.trim(a(b.currentTarget).val()),d=a(b.currentTarget).closest("[data-field]").data("field");a.isEmptyObject(this.filterColumnsPartial)&&(this.filterColumnsPartial={}),c?this.filterColumnsPartial[d]=c:delete this.filterColumnsPartial[d],this.searchText+="randomText",this.options.pageNumber=1,this.onSearch(b),this.trigger("column-search",d,c)}},w.prototype.clearFilterControl=function(){if(this.options.filterControl&&this.options.filterShowClear){var c=this,d=p(),e=j(c),f=e.closest("table"),g=e.find(k(c)),h=c.$toolbar.find(".search input"),i=0;if(a.each(c.options.valuesFilterControl,function(a,b){b.value=""}),o(c),!(g.length>0))return;if(this.filterColumnsPartial={},a(g[0]).trigger("INPUT"===g[0].tagName?"keyup":"change"),h.length>0&&c.resetSearch(),c.options.sortName!==f.data("sortName")||c.options.sortOrder!==f.data("sortOrder")){var l=e.find(b('[data-field="%s"]',a(g[0]).closest("table").data("sortName")));l.length>0&&(c.onSort(f.data("sortName"),f.data("sortName")),a(l).find(".sortable").trigger("click"))}clearTimeout(i),i=setTimeout(function(){d&&d.length>0&&a.each(d,function(a,b){void 0!==c.deleteCookie&&c.deleteCookie(b)})},c.options.searchTimeOut)}}}(jQuery); |