|
@@ -0,0 +1,34 @@
|
|
|
+(function () {
|
|
|
+ window.initStagTableFilters = function () {
|
|
|
+
|
|
|
+ function applyFilter(_elem) {
|
|
|
+ let term = $.trim(_elem.val()).toLowerCase(),
|
|
|
+ columnIndex = _elem.closest('td, th').index(),
|
|
|
+ trs = _elem.closest('table').find('tbody').find('tr');
|
|
|
+ trs.removeClass('stag-filter-hide');
|
|
|
+ if(!!term) {
|
|
|
+ trs.each(function () {
|
|
|
+ if ($(this).find('td:eq(' + columnIndex + ')').text().toLowerCase().indexOf(term) === -1) {
|
|
|
+ $(this).addClass('stag-filter-hide');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $(document)
|
|
|
+ .off('input.stag-table-filter').on('input.stag-table-filter', 'input[stag-table-filter]', function() { applyFilter($(this)); })
|
|
|
+ .off('change.stag-table-filter').on('change.stag-table-filter', 'input[stag-table-filter]', function() { applyFilter($(this)); })
|
|
|
+ .off('paste.stag-table-filter').on('paste.stag-table-filter', 'input[stag-table-filter]', function() { applyFilter($(this)); })
|
|
|
+
|
|
|
+ $(document)
|
|
|
+ .off('keyup.stag-table-filter')
|
|
|
+ .on('keyup.stag-table-filter', 'input[stag-table-filter]', function(_e) {
|
|
|
+ if(_e.which === 27) {
|
|
|
+ $(this).val('');
|
|
|
+ applyFilter($(this));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ addMCInitializer('stag-table-filter', window.initStagTableFilters);
|
|
|
+})();
|