/*! SearchPane 0.0.2 * 2018 SpryMedia Ltd - datatables.net/license */ /** * @summary SearchPane * @description Search Panes for DataTables columns * @version 0.0.2 * @author SpryMedia Ltd (www.sprymedia.co.uk) * @copyright Copyright 2018 SpryMedia Ltd. * * This source file is free software, available under the following license: * MIT license - http://datatables.net/license/mit * * This source file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details. * * For details please refer to: http://www.datatables.net */ (function(factory) { if (typeof define === 'function' && define.amd) { // AMD define(['jquery', 'datatables.net'], function($) { return factory($, window, document); }); } else if (typeof exports === 'object') { // CommonJS module.exports = function(root, $) { if (!root) { root = window; } if (!$ || !$.fn.dataTable) { $ = require('datatables.net')(root, $).$; } return factory($, root, root.document); }; } else { // Browser factory(jQuery, window, document); } })(function($, window, document, undefined) { 'use strict'; var DataTable = $.fn.dataTable; function SearchPanes(settings, opts) { var that = this; var table = new DataTable.Api(settings); this.classes = $.extend(true, {}, SearchPanes.classes); this.dom = { container: $('
').addClass(this.classes.container) }; this.c = $.extend(true, {}, SearchPanes.defaults, opts); this.s = { dt: table }; table.settings()[0].searchPane = this; table .columns(this.c.columns) .eq(0) .each(function(idx) { that._pane(idx); }); $(this.dom.container) .on('click', 'li', function() { that._toggle(this); }) .on('click', 'button.' + this.classes.clear, function() { that._clear($(this).closest('div.' + that.classes.pane.container)); }); this._attach(); } $.extend(SearchPanes.prototype, { rebuild: function() { var that = this; this.c.container.empty(); this.s.dt .columns(this.c.columns) .eq(0) .each(function(idx) { that._pane(idx); }); }, _attach: function() { var container = this.c.container; var host = typeof container === 'function' ? container(this.s.dt) : container; if (this.c.insert === 'prepend') { $(this.dom.container).prependTo(host); } else { $(this.dom.container).appendTo(host); } }, _binData: function(data) { var out = {}; for (var i = 0, ien = data.length; i < ien; i++) { var d = data[i]; if (!d) { continue; } if (!out[d]) { out[d] = 1; } else { out[d]++; } } return out; }, _clear: function(pane) { var classes = this.classes; var itemSelected = classes.item.selected; pane.find('li.' + itemSelected).removeClass(itemSelected); pane.removeClass(classes.pane.active); this.s.dt .column(pane.data('column')) .search('') .draw(); }, _pane: function(idx) { var classes = this.classes; var itemClasses = classes.item; var paneClasses = classes.pane; var table = this.s.dt; var column = table.column(idx); var colOpts = this._getOptions(idx); var list = $('