From 79d1914fe85b9aa271c36f561ca5a5543357c8b1 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 24 Jan 2025 22:23:20 -0500 Subject: [PATCH] Bump Plugin DataTables from 2.1.8 to 2.2.1 --- plugins/DataTables/datatables.css | 17 +- plugins/DataTables/datatables.js | 420 +++++++++++++++++++------- plugins/DataTables/datatables.min.css | 6 +- plugins/DataTables/datatables.min.js | 8 +- 4 files changed, 332 insertions(+), 119 deletions(-) diff --git a/plugins/DataTables/datatables.css b/plugins/DataTables/datatables.css index 2e9b2b58..3fedcdc3 100644 --- a/plugins/DataTables/datatables.css +++ b/plugins/DataTables/datatables.css @@ -4,10 +4,10 @@ * * To rebuild or modify this file with the latest versions of the included * software please visit: - * https://datatables.net/download/#bs4/dt-2.1.8 + * https://datatables.net/download/#bs4/dt-2.2.1 * * Included libraries: - * DataTables 2.1.8 + * DataTables 2.2.1 */ @charset "UTF-8"; @@ -43,6 +43,9 @@ table.dataTable tr.dt-hasChild td.dt-control:before { border-bottom: 0px solid transparent; border-right: 5px solid transparent; } +table.dataTable tfoot:empty { + display: none; +} html.dark table.dataTable td.dt-control:before, :root[data-bs-theme=dark] table.dataTable td.dt-control:before, @@ -251,6 +254,11 @@ table.dataTable th, table.dataTable td { box-sizing: border-box; } +table.dataTable th.dt-type-numeric, table.dataTable th.dt-type-date, +table.dataTable td.dt-type-numeric, +table.dataTable td.dt-type-date { + text-align: right; +} table.dataTable th.dt-left, table.dataTable td.dt-left { text-align: left; @@ -276,11 +284,6 @@ table.dataTable td.dt-empty { text-align: center; vertical-align: top; } -table.dataTable th.dt-type-numeric, table.dataTable th.dt-type-date, -table.dataTable td.dt-type-numeric, -table.dataTable td.dt-type-date { - text-align: right; -} table.dataTable thead th, table.dataTable thead td, table.dataTable tfoot th, diff --git a/plugins/DataTables/datatables.js b/plugins/DataTables/datatables.js index 0a220fb0..9a1a9b9d 100644 --- a/plugins/DataTables/datatables.js +++ b/plugins/DataTables/datatables.js @@ -4,34 +4,16 @@ * * To rebuild or modify this file with the latest versions of the included * software please visit: - * https://datatables.net/download/#bs4/dt-2.1.8 + * https://datatables.net/download/#bs4/dt-2.2.1 * * Included libraries: - * DataTables 2.1.8 + * DataTables 2.2.1 */ -/*! DataTables 2.1.8 +/*! DataTables 2.2.1 * © SpryMedia Ltd - datatables.net/license */ -/** - * @summary DataTables - * @description Paginate, search and order HTML tables - * @version 2.1.8 - * @author SpryMedia Ltd - * @contact www.datatables.net - * @copyright SpryMedia Ltd. - * - * This source file is free software, available under the following license: - * MIT license - https://datatables.net/license - * - * 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: https://www.datatables.net - */ - (function( factory ) { "use strict"; @@ -441,7 +423,6 @@ thead = $('').appendTo($this); } oSettings.nTHead = thead[0]; - $('tr', thead).addClass(oClasses.thead.row); var tbody = $this.children('tbody'); if ( tbody.length === 0 ) { @@ -456,7 +437,6 @@ tfoot = $('').appendTo($this); } oSettings.nTFoot = tfoot[0]; - $('tr', tfoot).addClass(oClasses.tfoot.row); // Copy the data index array oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); @@ -539,7 +519,7 @@ * * @type string */ - builder: "bs4/dt-2.1.8", + builder: "bs4/dt-2.2.1", /** @@ -2173,6 +2153,10 @@ var width = _fnColumnsSumWidth(settings, [i], false, false); cols[i].colEl.css('width', width); + + if (settings.oScroll.sX) { + cols[i].colEl.css('min-width', width); + } } } @@ -3240,9 +3224,13 @@ // Add the number of cells needed to make up to the number of columns if (row.length === 1) { - var cells = $('td, th', row); + var cellCount = 0; + + $('td, th', row).each(function () { + cellCount += this.colSpan; + }); - for ( i=cells.length, ien=columns.length ; i') .html( columns[i][titleProp] || '' ) .appendTo( row ); @@ -3254,9 +3242,11 @@ if (side === 'header') { settings.aoHeader = detected; + $('tr', target).addClass(classes.thead.row); } else { settings.aoFooter = detected; + $('tr', target).addClass(classes.tfoot.row); } // Every cell needs to be passed through the renderer @@ -4519,7 +4509,7 @@ // So the array reference doesn't break set the results into the // existing array displayRows.length = 0; - displayRows.push.apply(displayRows, rows); + _fnArrayApply(displayRows, rows); } } @@ -5247,8 +5237,11 @@ // [].find, but it wasn't supported in Chrome until Sept 2015, and DT has 10 year // browser support var firstTr = null; + var start = _fnDataSource( settings ) !== 'ssp' + ? settings._iDisplayStart + : 0; - for (i=settings._iDisplayStart ; i col is set to and correct if needed @@ -5273,6 +5266,10 @@ if (colWidth !== colSizes[i].width) { colEl.style.width = colSizes[i].width + 'px'; + + if (scroll.sX) { + colEl.style.minWidth = colSizes[i].width + 'px'; + } } } } @@ -5365,6 +5362,14 @@ i, column, columnIdx; var styleWidth = table.style.width; + var containerWidth = _fnWrapperWidth(settings); + + // Don't re-run for the same width as the last time + if (containerWidth === settings.containerWidth) { + return false; + } + + settings.containerWidth = containerWidth; // If there is no width applied as a CSS style or as an attribute, we assume that // the width is intended to be 100%, which is usually is in CSS, but it is very @@ -5422,6 +5427,8 @@ // browser will collapse it. If this width is smaller than the // width the column requires, then it will have no effect if ( scrollX ) { + this.style.minWidth = width; + $( this ).append( $('
').css( { width: width, margin: 0, @@ -5490,15 +5497,15 @@ // If there is no width attribute or style, then allow the table to // collapse - if ( tmpTable.width() < tableContainer.clientWidth && tableWidthAttr ) { - tmpTable.width( tableContainer.clientWidth ); + if ( tmpTable.outerWidth() < tableContainer.clientWidth && tableWidthAttr ) { + tmpTable.outerWidth( tableContainer.clientWidth ); } } else if ( scrollY ) { - tmpTable.width( tableContainer.clientWidth ); + tmpTable.outerWidth( tableContainer.clientWidth ); } else if ( tableWidthAttr ) { - tmpTable.width( tableWidthAttr ); + tmpTable.outerWidth( tableWidthAttr ); } // Get the width of each column in the constructed table @@ -5531,20 +5538,55 @@ } if ( (tableWidthAttr || scrollX) && ! settings._reszEvt ) { - var bindResize = function () { - $(window).on('resize.DT-'+settings.sInstance, DataTable.util.throttle( function () { - if (! settings.bDestroying) { - _fnAdjustColumnSizing( settings ); - } - } ) ); - }; + var resize = DataTable.util.throttle( function () { + var newWidth = _fnWrapperWidth(settings); - bindResize(); + // Don't do it if destroying or the container width is 0 + if (! settings.bDestroying && newWidth !== 0) { + _fnAdjustColumnSizing( settings ); + } + } ); + + // For browsers that support it (~2020 onwards for wide support) we can watch for the + // container changing width. + if (window.ResizeObserver) { + // This is a tricky beast - if the element is visible when `.observe()` is called, + // then the callback is immediately run. Which we don't want. If the element isn't + // visible, then it isn't run, but we want it to run when it is then made visible. + // This flag allows the above to be satisfied. + var first = $(settings.nTableWrapper).is(':visible'); + + settings.resizeObserver = new ResizeObserver(function (e) { + if (first) { + first = false; + } + else { + resize(); + } + }); + + settings.resizeObserver.observe(settings.nTableWrapper); + } + else { + // For old browsers, the best we can do is listen for a window resize + $(window).on('resize.DT-'+settings.sInstance, resize); + } settings._reszEvt = true; } } + /** + * Get the width of the DataTables wrapper element + * + * @param {*} settings DataTables settings object + * @returns Width + */ + function _fnWrapperWidth(settings) { + return $(settings.nTableWrapper).is(':visible') + ? $(settings.nTableWrapper).width() + : 0; + } /** * Get the maximum strlen for each data column @@ -6153,15 +6195,26 @@ return; } + // Sort state saving uses [[idx, order]] structure. + var sorting = []; + _fnSortResolve(settings, sorting, settings.aaSorting ); + /* Store the interesting variables */ + var columns = settings.aoColumns; var state = { time: +new Date(), start: settings._iDisplayStart, length: settings._iDisplayLength, - order: $.extend( true, [], settings.aaSorting ), + order: sorting.map(function (sort) { + // If a column name is available, use it + return columns[sort[0]] && columns[sort[0]].sName + ? [ columns[sort[0]].sName, sort[1] ] + : sort.slice(); + } ), search: $.extend({}, settings.oPreviousSearch), columns: settings.aoColumns.map( function ( col, i ) { return { + name: col.sName, visible: col.bVisible, search: $.extend({}, settings.aoPreSearchCols[i]) }; @@ -6209,6 +6262,8 @@ function _fnImplementState ( settings, s, callback) { var i, ien; var columns = settings.aoColumns; + var currentNames = _pluck(settings.aoColumns, 'sName'); + settings._bLoadingState = true; // When StateRestore was introduced the state could now be implemented at any time @@ -6238,13 +6293,6 @@ return; } - // Number of columns have changed - all bets are off, no restore of settings - if ( s.columns && columns.length !== s.columns.length ) { - settings._bLoadingState = false; - callback(); - return; - } - // Store the saved state so it might be accessed at any time settings.oLoadedState = $.extend( true, {}, s ); @@ -6278,10 +6326,23 @@ if ( s.order !== undefined ) { settings.aaSorting = []; $.each( s.order, function ( i, col ) { - settings.aaSorting.push( col[0] >= columns.length ? - [ 0, col[1] ] : - col - ); + var set = [ col[0], col[1] ]; + + // A column name was stored and should be used for restore + if (typeof col[0] === 'string') { + var idx = currentNames.indexOf(col[0]); + + // Find the name from the current list of column names, or fallback to index 0 + set[0] = idx >= 0 + ? idx + : 0; + } + else if (set[0] >= columns.length) { + // If a column name, but it is out of bounds, set to 0 + set[0] = 0; + } + + settings.aaSorting.push(set); } ); } @@ -6292,31 +6353,65 @@ // Columns if ( s.columns ) { - for ( i=0, ien=s.columns.length ; i= 0) { + set.push(s.columns[idx]); + } + else { + // No matching column name in the state's columns, so this might be a new + // column and thus can't have a state already. + set.push({}); + } } else { - columns[i].bVisible = col.visible; + // If no name, but other columns did have a name, then there is no knowing + // where this one came from originally so it can't be restored. + set.push({}); + } + } + } + + // If the number of columns to restore is different from current, then all bets are off. + if (set.length === columns.length) { + for ( i=0, ien=set.length ; i 1 && // prevent infinite - $(host).height() >= ($(buttonEls[0]).outerHeight() * 2) - 10 - ) { - _pagingDraw(settings, host, $.extend({}, opts, { buttons: opts.buttons - 2 })); + if (buttonEls.length) { + var outerHeight = $(buttonEls[0]).outerHeight(); + + if ( + opts.buttons > 1 && // prevent infinite + outerHeight > 0 && // will be 0 if hidden + $(host).height() >= (outerHeight * 2) - 10 + ) { + _pagingDraw(settings, host, $.extend({}, opts, { buttons: opts.buttons - 2 })); + } } } @@ -13336,7 +13548,6 @@ switch ( button ) { case 'ellipsis': o.display = '…'; - o.disabled = true; break; case 'first': @@ -13523,7 +13734,7 @@ // Save text node content for macro updating var textNodes = []; - Array.from(div.find('label')[0].childNodes).forEach(function (el) { + Array.prototype.slice.call(div.find('label')[0].childNodes).forEach(function (el) { if (el.nodeType === Node.TEXT_NODE) { textNodes.push({ el: el, @@ -13541,7 +13752,6 @@ // Next, the select itself, along with the options var select = $('