Skip to content

Commit

Permalink
Datatables improvements (#833)
Browse files Browse the repository at this point in the history
* fix mark.ignorePunctuation type

* fix quantity, number and temperature sort

* fix double property scan
  • Loading branch information
thomas-topway-it committed May 7, 2024
1 parent a936970 commit a1527d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 16 additions & 8 deletions formats/datatables/DataTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -801,7 +802,7 @@ private function formatOptions( $params ) {
'lengthMenu' => "number",
'buttons' => "string",
'searchPanes.columns' => "number",
'mark.ignorePunctuation' => "number",
'mark.ignorePunctuation' => "",
// ...
];

Expand All @@ -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 );
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion formats/datatables/resources/ext.srf.formats.datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a1527d4

Please sign in to comment.