From a1527d4e35e88dfeeff23802dd1643206a1bb9ec Mon Sep 17 00:00:00 2001 From: thomas-topway-it Date: Tue, 7 May 2024 14:43:37 +0400 Subject: [PATCH] Datatables improvements (#833) * fix mark.ignorePunctuation type * fix quantity, number and temperature sort * fix double property scan --- formats/datatables/DataTables.php | 24 ++++++++++++------- .../resources/ext.srf.formats.datatables.js | 3 ++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/formats/datatables/DataTables.php b/formats/datatables/DataTables.php index 17fdafd3..4703d778 100644 --- a/formats/datatables/DataTables.php +++ b/formats/datatables/DataTables.php @@ -548,12 +548,13 @@ protected function getResultText( QueryResult $res, $outputmode ) { $formattedOptions = $this->formatOptions( $datatablesOptions ); + // for the order @see https://github.com/SemanticMediaWiki/SemanticResultFormats/issues/825 + $result = $this->getResultJson( $res, $outputmode ); + // @TODO use only one between printouts and printrequests $resultArray = $res->toArray(); $printrequests = $resultArray['printrequests']; - $result = $this->getResultJson( $res, $outputmode ); - $this->htmlTable = new HtmlTable(); foreach ( $headerList as $text ) { $attributes = []; @@ -801,7 +802,7 @@ private function formatOptions( $params ) { 'lengthMenu' => "number", 'buttons' => "string", 'searchPanes.columns' => "number", - 'mark.ignorePunctuation' => "number", + 'mark.ignorePunctuation' => "", // ... ]; @@ -810,12 +811,19 @@ private function formatOptions( $params ) { // transform csv to array if ( array_key_exists( $key, $arrayTypes ) ) { - $value = preg_split( "/\s*,\s*/", $value, -1, PREG_SPLIT_NO_EMPTY ); - if ( $arrayTypes[$key] === 'number' ) { - $value = array_map( static function ( $value ) { - return (int)$value; - }, $value ); + // https://markjs.io/#mark + if ( $arrayTypes[$key] === '' ) { + $value = str_split( $value ); + + } else { + $value = preg_split( "/\s*,\s*/", $value, -1, PREG_SPLIT_NO_EMPTY ); + + if ( $arrayTypes[$key] === 'number' ) { + $value = array_map( static function ( $value ) { + return (int)$value; + }, $value ); + } } } diff --git a/formats/datatables/resources/ext.srf.formats.datatables.js b/formats/datatables/resources/ext.srf.formats.datatables.js index b5d7344c..1a632e0d 100644 --- a/formats/datatables/resources/ext.srf.formats.datatables.js +++ b/formats/datatables/resources/ext.srf.formats.datatables.js @@ -579,7 +579,8 @@ // value for all columns if (!options.columns.type) { options.columns.type = - entityCollation === "numeric" && property.typeid === "_wpg" + ( entityCollation === 'numeric' && property.typeid === '_wpg' ) + || [ '_num', '_tem', '_qty' ].indexOf(property.typeid) !== -1 ? "any-number" : null; }