Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use orthogonal data for DataTables #865

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion formats/datatables/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions formats/datatables/DataTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -573,7 +563,7 @@ protected function getResultText( QueryResult $res, $outputmode ) {

foreach ( $rows as $cell ) {
$this->htmlTable->cell(
( $cell === '' ? ' ' : $cell ),
( $cell['display'] === '' ? ' ' : $cell['display'] ),
[]
);
}
Expand Down Expand Up @@ -993,7 +983,13 @@ public function getCellContent( $label, $dataValues, $outputMode, $isSubject, $p
$html = implode( $this->params['sep'], $values );
}

return $html;
$sortKey = $dataValues[0]->getDataItem()->getSortKey();

return [
'display' => $html,
'filter' => $sortKey,
'sort' => $sortKey
];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions formats/datatables/SearchPanes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '' ];
Expand Down Expand Up @@ -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' => '' ];
Expand Down
41 changes: 20 additions & 21 deletions formats/datatables/resources/ext.srf.formats.datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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++;
}
}

Expand Down Expand Up @@ -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;
},
});
}
Expand Down Expand Up @@ -544,7 +545,7 @@
num: {
null: null,
},
},
}
};
} else {
options.dom = options.dom.replace("Q", "");
Expand Down Expand Up @@ -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(
Expand All @@ -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]
Expand Down
38 changes: 0 additions & 38 deletions resources/jquery/datatables/jquery.dataTables.extras.js

This file was deleted.

2 changes: 1 addition & 1 deletion tests/qunit/formats/ext.srf.formats.datatables.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading