diff --git a/Resources.php b/Resources.php index 1d6a917d..21fbb5e6 100644 --- a/Resources.php +++ b/Resources.php @@ -1008,8 +1008,7 @@ 'resources/jquery/datatables/object_hash.js', 'resources/jquery/datatables/jquery.mark.min.js', 'resources/jquery/datatables/datatables.mark.min.js', - 'resources/jquery/datatables/datatables.min.js', - 'resources/jquery/datatables/jquery.dataTables.extras.js', + 'resources/jquery/datatables/datatables.min.js' ], 'styles' => [ 'resources/jquery/datatables/datatables.mark.min.css', diff --git a/formats/datatables/Api.php b/formats/datatables/Api.php index 2ed3c1b0..d83cfb75 100644 --- a/formats/datatables/Api.php +++ b/formats/datatables/Api.php @@ -111,7 +111,7 @@ public function execute() { if ( $hasMainlabel && trim( $parameters['mainlabel'] ) === '-' ) { continue; } - // match something like |?=abc |+ datatables-columns.type=any-number |+template=mytemplate + // match something like |?=abc |+template=mytemplate } // create printrequest from request mode, label, property name, output format, parameters diff --git a/formats/datatables/DataTables.php b/formats/datatables/DataTables.php index 9aafae43..1dccf064 100644 --- a/formats/datatables/DataTables.php +++ b/formats/datatables/DataTables.php @@ -267,16 +267,6 @@ public function getParamDefinitions( array $definitions ) { //////////////// datatables columns - // only the options whose value has a sense to - // use for all columns, otherwise use (for single printouts) - // |?printout name |+ datatables-columns.type = string - - $params['datatables-columns.type'] = [ - 'type' => 'string', - 'message' => 'srf-paramdesc-datatables-library-option', - 'default' => '', - ]; - $params['datatables-columns.width'] = [ 'type' => 'string', 'message' => 'srf-paramdesc-datatables-library-option', @@ -573,7 +563,7 @@ protected function getResultText( QueryResult $res, $outputmode ) { foreach ( $rows as $cell ) { $this->htmlTable->cell( - ( $cell === '' ? ' ' : $cell ), + ( $cell['display'] === '' ? ' ' : $cell['display'] ), [] ); } @@ -993,7 +983,14 @@ public function getCellContent( $label, $dataValues, $outputMode, $isSubject, $p $html = implode( $this->params['sep'], $values ); } - return $html; + // $dataValues could be empty + $sortKey = array_key_exists( 0, $dataValues ) ? $dataValues[0]->getDataItem()->getSortKey() : ''; + + return [ + 'display' => $html, + 'filter' => $sortKey, + 'sort' => $sortKey + ]; } /** diff --git a/formats/datatables/SearchPanes.php b/formats/datatables/SearchPanes.php index eddaabcf..c4fd20d1 100644 --- a/formats/datatables/SearchPanes.php +++ b/formats/datatables/SearchPanes.php @@ -384,7 +384,7 @@ private function getPanesOptions( $printRequest, $canonicalLabel, $searchPanesOp $outputMode, $isSubject, $propTypeid - ); + )['display']; if ( !array_key_exists( $cellContent, $groups ) ) { $groups[$cellContent] = [ 'count' => 0, 'value' => '' ]; @@ -710,7 +710,7 @@ private function searchPanesMainlabel( $printRequest, $searchPanesOptions, $sear [ $dataValue ], $outputMode, $isSubject - ); + )['display']; if ( !array_key_exists( $cellContent, $groups ) ) { $groups[$cellContent] = [ 'count' => 0, 'value' => '' ]; diff --git a/formats/datatables/resources/ext.srf.formats.datatables.js b/formats/datatables/resources/ext.srf.formats.datatables.js index cce48b0d..344cf2fa 100644 --- a/formats/datatables/resources/ext.srf.formats.datatables.js +++ b/formats/datatables/resources/ext.srf.formats.datatables.js @@ -164,16 +164,17 @@ for (var i in data) { for (var ii in ret) { - if (data[i][ii] === "") { + var cellData = data[i][ii]; + if (!cellData) { continue; } dataLength[ii]++; var label; if (options.searchPanes.htmlLabels === false) { - div.innerHTML = data[i][ii]; + div.innerHTML = cellData.display; label = div.textContent || div.innerText || ""; } else { - label = data[i][ii]; + label = cellData.display; } // this will exclude images as well if @@ -182,15 +183,15 @@ continue; } - if (!(data[i][ii] in ret[ii])) { - ret[ii][data[i][ii]] = { + if (!(cellData.display in ret[ii])) { + ret[ii][cellData.display] = { label: label, - value: data[i][ii], + value: cellData.display, count: 0, }; } - ret[ii][data[i][ii]].count++; + ret[ii][cellData.display].count++; } } @@ -246,7 +247,7 @@ columnDefs[i].searchPanes.options.push({ label: searchPanesOptions[i][ii].label, value: function (rowData, rowIdx) { - return rowData[i] === searchPanesOptions[i][ii].value; + return rowData[i].display === searchPanesOptions[i][ii].value; }, }); } @@ -544,7 +545,7 @@ num: { null: null, }, - }, + } }; } else { options.dom = options.dom.replace("Q", ""); @@ -576,15 +577,9 @@ var columnDefs = []; $.map(printrequests, function (property, index) { - // @see https://datatables.net/reference/option/columns.type - // value for all columns - if (!options.columns.type) { - options.columns.type = - ( entityCollation === 'numeric' && property.typeid === '_wpg' ) - || [ '_num', '_tem', '_qty' ].indexOf(property.typeid) !== -1 - ? "any-number" - : null; - } + var isNumeric = ( entityCollation === 'numeric' && property.typeid === '_wpg' ) + || [ '_num', '_tem', '_qty' ].indexOf(property.typeid) !== -1; + options.columns.type = isNumeric ? 'num' : 'string'; columnDefs.push( $.extend( @@ -597,9 +592,13 @@ className: "smwtype" + property.typeid, targets: [index], - // @FIXME https://datatables.net/reference/option/columns.searchBuilderType - // implement in the proper way - searchBuilderType: "string", + // https://datatables.net/reference/option/columns.render + render: { + _: 'display', + display: 'display', + filter: 'filter', + sort: 'sort' + }, }, options.columns, data.printoutsParametersOptions[index] diff --git a/resources/jquery/datatables/jquery.dataTables.extras.js b/resources/jquery/datatables/jquery.dataTables.extras.js deleted file mode 100644 index 8ad14dd9..00000000 --- a/resources/jquery/datatables/jquery.dataTables.extras.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * SRF DataTables JavaScript Printer using the SMWAPI - * - * @see http://datatables.net/ - * - * @licence GPL-2.0-or-later - * @author thomas-topway-it for KM-A - * @credits mwjames (ext.smw.tableprinter.js) - */ - -(function ($) { - - // @see https://datatables.net/plug-ins/sorting/any-number - var _anyNumberSort = function (a, b, high) { - var tmpA = document.createElement("DIV"); - tmpA.innerHTML = a; - a = tmpA.textContent || tmpA.innerText || ""; - - var tmpB = document.createElement("DIV"); - tmpB.innerHTML = b; - b = tmpB.textContent || tmpB.innerText || ""; - - return a.localeCompare(b, undefined, { - numeric: true, - sensitivity: "base", - }); - }; - - $.extend($.fn.dataTableExt.oSort, { - "any-number-asc": function (a, b) { - return _anyNumberSort(a, b, Number.POSITIVE_INFINITY); - }, - "any-number-desc": function (a, b) { - return _anyNumberSort(a, b, Number.NEGATIVE_INFINITY) * -1; - }, - }); -})(jQuery); - diff --git a/tests/qunit/formats/ext.srf.formats.datatables.test.js b/tests/qunit/formats/ext.srf.formats.datatables.test.js index ed611210..87d911d8 100644 --- a/tests/qunit/formats/ext.srf.formats.datatables.test.js +++ b/tests/qunit/formats/ext.srf.formats.datatables.test.js @@ -13,7 +13,7 @@ QUnit.module( 'ext.srf.formats.datatables', QUnit.newMwEnvironment() ); var pass = 'Passes because '; - var context = $( '