Sort
Allows sorting of grid by clicking (or tapping) headers, also displays which columns grid is sorted by (numbered if using multisort). Use modifier keys for multisorting: [Ctrl/CMD + click] to add sorter, [Ctrl/CMD + Alt + click] to remove sorter. The actual sorting is done by the store, see Store.sort().
//<code-header>
fiddle.title = 'Sort';
//</code-header>
targetElement.innerHTML = '<p>Sorted by Name, click a header to sort ascending, again to sort descending</p>';
const grid = new Grid({
appendTo : targetElement,
// makes grid as high as it needs to be to fit rows
autoHeight : true,
features : {
// sorting by name
sort : 'name'
},
data : DataGenerator.generateData(5),
columns : [
{ field : 'name', text : 'Name', flex : 1 },
{ field : 'city', text : 'City', flex : 1 },
{ type : 'number', field : 'score', text : 'Score', flex : 1 },
{ type : 'number', field : 'age', text : 'Age (no sort)', flex : 1, sortable : false }
]
});// sorting feature is enabled, no default value though
const grid = new Grid({
features : {
sort : true
}
});
// use initial sorting
const grid = new Grid({
features : {
sort : 'name'
}
});
// can also be specified on the store
const grid = new Grid({
store : {
sorters : [
{ field : 'name', ascending : false }
]
}
});
// custom sorting function can also be specified on the store
const grid = new Grid({
store : {
sorters : [{
fn : (recordA, recordB) => {
// apply custom logic, for example:
return recordA.name.length < recordB.name.length ? -1 : 1;
}
}]
}
});
For info on programmatically handling sorting, see StoreSort:
const grid = new Grid({ });
// Programmatic sorting of the store, Grids rows and UI will be updated
grid.store.sort('age');
Grid columns can define custom sorting functions (see Column.sortable).
If this feature is configured with prioritizeColumns: true, those functions will also be used when sorting
programmatically:
const grid = new Grid({
columns : [
{
field : 'age',
text : 'Age',
+ sortable(lhs, rhs) {
+ // Custom sorting, see Array#sort
+ }
}
],
features : {
sort : {
+ prioritizeColumns : true
}
}
});
// Sortable fn will also be used when sorting programmatically
grid.store.sort('age');
This feature is enabled by default.
Configs
13
Configs
13Other
Enable multi sort
Use custom sorting functions defined on columns also when programmatically sorting by the columns field.
const grid = new Grid({
columns : [
{
field : 'age',
text : 'Age',
sortable(lhs, rhs) {
// Custom sorting, see Array#sort
}
}
],
features : {
sort : {
prioritizeColumns : true
}
}
});
grid.store.sort('age');
Set to false to not show the sort icon when hovering a Column header.
By default, clicking anywhere on the header text toggles the sorting state of a column.
Configure this as false to only toggle the sorting state of a column on click of the
"arrow" icon within the grid header.
Misc
Properties
16
Properties
16Common
Class hierarchy
Other
Set to false to not show the sort icon when hovering a Column header.
Functions
28
Functions
28Configuration
Events
Misc
Other
Events
5
Events
5Event handlers
5
Event handlers
5Typedefs
1
Typedefs
1CSS variables
3
CSS variables
3| Name | Description |
|---|---|
--b-sort-header-icon | Column header sort icon (font icon) |
--b-sort-header-index-font-size | Column header sorter index font size (displayed when multi-sorting) |
--b-sort-header-index-color | Column header sorter index color (displayed when multi-sorting) |