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().

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

Common

disabledInstancePlugin
listenersEvents

Other

multiSort: Boolean= true

Enable multi sort

prioritizeColumns: Boolean= false

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.

toggleOnHeaderClick: Boolean= false

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

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

16

Common

disabledInstancePlugin

Class hierarchy

isSort: Boolean= truereadonly
Identifies an object as an instance of Sort class, or subclass thereof.
isSort: Boolean= truereadonlystatic
Identifies an object as an instance of Sort class, or subclass thereof.
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable

Other

Set to false to not show the sort icon when hovering a Column header.

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

28

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

LstaticLocalizable
onEvents
relayAllEvents
triggerEvents
unEvents

Events

5
catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

5
onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

1

CSS variables

3
NameDescription
--b-sort-header-iconColumn header sort icon (font icon)
--b-sort-header-index-font-sizeColumn header sorter index font size (displayed when multi-sorting)
--b-sort-header-index-colorColumn header sorter index color (displayed when multi-sorting)