File modules/template_engine/components/html/component_table/table.min.js
Last commit: Tue Mar 1 23:03:32 2022 +0100 dankert New: OQuery support for 'parent(selector)' and 'parents(selector)'
1 import $ from '../../../../cms/ui/themes/default/script/jquery-global.min.js'; 2 export default function(element ) { 3 let calculateOrderList = function() { 4 let order = new Array(); 5 $(element).find('.or-table--sortable').find('tbody > tr.or-data').each(function () { 6 let objectid = $(this).data('id'); 7 order.push(objectid); 8 }); 9 $(element).find('input[name=order]').val(order.join(',')); 10 }; 11 calculateOrderList(); 12 let sortableElement = $(element).find('.or-table--sortable > tbody').get(0); 13 if ( sortableElement ) { 14 let sortable = import( './sortable.min.js' ); 15 sortable.then( Sortable => { 16 new Sortable(sortableElement, {onUpdate: calculateOrderList}) 17 } ); 18 } 19 $(element).find('tr.headline > td > input.checkbox').click( function() { 20 $(this).closest('table').find('tr.or-data > td > input.or-checkbox').attr('checked',Boolean( $(this).attr('checked') ) ); 21 }); 22 $(element).find('.or-table-filter > input').keyup( function() { 23 let filterExpression = $(this).val().toLowerCase(); 24 let table = $(this).parents('.or-table-wrapper').find('table'); 25 table.addClass('loader'); 26 setTimeout( () => { 27 table.find('tr:not(.or-table-header)').each(function () { 28 let $row = $(this); 29 if ( $row.text().toLowerCase().indexOf(filterExpression) > -1) 30 $row.removeClass('-off'); 31 else 32 $row.addClass('-off'); 33 } ); 34 table.removeClass('loader'); 35 }, 50); 36 } ); 37 $(element).find('table > tbody > tr.or-table-header > td, table > tbody > tr > th').click( function() { 38 let column = $(this); 39 let table = column.closest('table'); 40 table.addClass('loader'); 41 let isAscending = !column.hasClass('sort-asc'); 42 table.find('tr.or-table-header > td, tr > th').removeClass('sort-asc').removeClass('sort-desc'); 43 if ( isAscending ) column.addClass('sort-asc'); else column.addClass('sort-desc'); 44 Promise.resolve().then( () => { 45 let rows = table.find('tr:not(.or-table-header)').toArray().sort(comparer(column.index())) 46 if (!isAscending) { 47 rows = rows.reverse() 48 } 49 for (let i = 0; i < rows.length; i++) { 50 table.append( $(rows[i]) ); 51 } 52 table.removeClass('loader'); 53 }); 54 } ); 55 function comparer(index) { 56 return function(a, b) { 57 let valA = getCellValue(a, index), valB = getCellValue(b, index) 58 return isNumeric(valA) && isNumeric(valB) ? valA - valB : valA.toString().localeCompare(valB) 59 } 60 } 61 function getCellValue(row, index) { 62 let x = $(row).children('td').eq(index); 63 return $(row).children('td').eq(index).text(); 64 } 65 function isNumeric(n) { 66 return !isNaN(parseFloat(n)) && isFinite(n); 67 } 68 };
Downloadmodules/template_engine/components/html/component_table/table.min.js
History Tue, 1 Mar 2022 23:03:32 +0100 dankert New: OQuery support for 'parent(selector)' and 'parents(selector)' Sat, 18 Dec 2021 03:47:23 +0100 dankert New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments.