Bug 27680: Add support for sorting fields with multiple data points

This patch adds proper handling for sorting a single column that is
constructed of multiple data entities.. i.e `"data": "string1:string2"`

It does NOT add support for filtering on multiple columns yet.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2021-02-12 13:14:16 +00:00 committed by Jonathan Druart
parent ba7f51f3d1
commit fa1671aba5
3 changed files with 5 additions and 4 deletions

View file

@ -92,9 +92,10 @@ Generates the DBIC order_by attributes based on I<$params>, and merges into I<$a
if ( defined $args->{params}->{_order_by} ) {
my $order_by = $args->{params}->{_order_by};
$order_by = [ split(/,/, $order_by) ] if ( index(',',$order_by) == -1);
if ( reftype($order_by) and reftype($order_by) eq 'ARRAY' ) {
my @order_by = map { _build_order_atom({ string => $_, result_set => $result_set }) }
@{ $args->{params}->{_order_by} };
@{ $order_by };
$attributes->{order_by} = \@order_by;
}
else {

View file

@ -72,7 +72,7 @@
"required": false,
"description": "Sorting criteria",
"type": "array",
"collectionFormat": "pipes",
"collectionFormat": "csv",
"items": {
"type": "string"
}

View file

@ -637,9 +637,9 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
order.forEach(function (e,i) {
var order_col = e.column;
var order_by = options.columns[order_col].data;
order_by = order_by.split(':')[0];
order_by = order_by.split(':');
var order_dir = e.dir == 'asc' ? '+' : '-';
dataSet._order_by = order_dir + (!order_by.includes('.')?'me.'+order_by:order_by);
dataSet._order_by = order_by.map(x => order_dir + (!x.includes('.')?'me.'+x:x)).join(',');
});
}