Are you an LLM? You can read better optimized documentation at /front/component/ma-table/sorting.md for this page in Markdown format
Table Sorting β
Supports multiple sorting methods: built-in sorting, custom sorting, multi-level sorting, etc.
Sorting Demo β
Features β
Sorting Types β
- Built-in Sorting: Simply set
sortable: true
to use the default sorting algorithm - Custom Sorting: Set
sortable: 'custom'
and implement custom sorting logic through event listeners - Disable Sorting: Omit
sortable
or set it tofalse
Sorting Control β
- Default Sorting: Set initial table sorting state via
defaultSort
- Sort Order: Control sorting toggle sequence via
sortOrders
- Sort Events: Listen to
sort-change
event to track sorting changes
Configuration Examples β
Basic Sorting β
javascript
const columns = [
{
label: 'Product Name',
prop: 'name',
sortable: true // Enable built-in sorting
},
{
label: 'Price',
prop: 'price',
sortable: 'custom' // Custom sorting
}
]
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Sorting Configuration β
javascript
const options = {
// Set default sorting
defaultSort: {
prop: 'price',
order: 'descending'
},
// Listen to sorting events
on: {
onSortChange: ({ column, prop, order }) => {
console.log('Sort changed:', column.label, order)
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Custom Sort Order β
javascript
const columns = [
{
label: 'Sales',
prop: 'sales',
sortable: true,
// Custom sort order: ascending -> descending -> no sort
sortOrders: ['ascending', 'descending', null]
}
]
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Sorting Parameters β
Parameter | Description | Type | Default |
---|---|---|---|
sortable | Whether the column is sortable | boolean | 'custom' | false |
sortMethod | Sorting method used for data | Function(a, b) | - |
sortBy | Specifies which property to sort by | string | array | Function(row, index) | - |
sortOrders | Rotation order of sorting strategies | array | ['ascending', 'descending', null] |
defaultSort | Default sorted column's prop and order | object | - |
Events β
Event | Description | Parameters |
---|---|---|
sort-change | Triggered when table sorting conditions change | { column, prop, order } |
Where order
can be:
'ascending'
: Ascending'descending'
: Descendingnull
: Cancel sorting