I found an example here https://jdanyow.github.io/aurelia-converters-sample/ (search for SortValueConverter) - Just need to somehow extend the toView function:
export class SortValueConverter {
toView(array, propertyName, direction) {
var factor = direction === 'ascending' ? 1 : -1;
return array
.slice(0)
.sort((a, b) => {
return (a[propertyName] - b[propertyName]) * factor
});
}
}
so that it does not only sort each row, but so that it:
- sorts each row group object - inside the array of table rows - which has the boolean isGroup: true set
- Together with sorting the row itself, it should however also sort the row group children belonging under each group
- And of course these rows would also need to be moved together with their group rows, so they stay below the group row.
In my js code I've flattened the array, so I can show it in a table. isGroup:true/false marks when a new group begins.
- robots (isGroup: true)
- R2-D2
- terminator
- wall-e
- robocop
- C-3PO
- animals (isGroup:true)
- dog
- shark
- cat
- monkey
How could you rewrite the sort value converter (ideally) to sort both row groups and row group children eg. alphabetically asc/desc. I guess it doesn't have to be done using a value converter but could in theory just be done directly on the array in the js code, but I think the best solution would be to extend the sort value converter to support this row grouping also.
To keep this example as "simple" as possible, let's reduce the row objects to a bare minimum of:
{
name: 'group or robot name'
isGroup: true/false
}
so eg.
[
{
name: 'robots',
isGroup: true
},
{
name: 'R2-D2',
isGroup: false
},
{
name: 'terminator',
isGroup: false
},
{
name: 'wall-e',
isGroup: false
},
{
name: 'robocop',
isGroup: false
},
{
name: 'C-3PO',
isGroup: false
},
{
name: 'animals',
isGroup: true
},
{
name: 'dog',
isGroup: false
},
{
name: 'shark',
isGroup: false
},
{
name: 'cat',
isGroup: false
},
{
name: 'monkey',
isGroup: false
}
]
Any ideas?