EnTableSortable
Preview
Props
| Name | Description | Default | Control |
|---|---|---|---|
| headings | The column definitions, as array<SortableTableHeading> | unknown | complex object |
| rows | An array of table data containing objects or array of strings or numbers, where each object/array is a row of table data. Objects are recommended for full feature use. array | […] | complex object |
| groups | Optional grouped table data. When provided (non-empty), the table renders one
array | […] | complex object |
| showGroupHeadings | Whether each group opens with a heading row. Turn it off when the group is already identifiable from the rows themselves — a column repeating the group name, or a totals row that names it — and the heading would just be a redundant band. A group select-all still forces the row to render, since that is where its checkbox lives. boolean | true | |
| groupSelectAll | Adds a select-all checkbox to each group's heading row that toggles only that
group's rows within the shared selection. Requires boolean | false | |
| rowType | The type of each row of the table. string | "object" | |
| headerClass | CSS class that will be applied to all table headers. string | "" | |
| wrapHeader | Whether or not the text in the table headers should be wrapped. boolean | true | |
| enableBulkAction | Enables checkboxes for bulk actions. NOTE: must have a v-model binding to an array to work properly.
Do NOT also add a manual boolean | false | |
| bulkActionProperty | Sets a property to pull from each selected item instead of the full object. e.g. set to 'Id' if you want to only include the Id from the selected objects. string | null | |
| totals | Optional grand totals rendered in a object | null | complex object |
| fixedLayout | Switches the table to a fixed layout, which makes column widths absolute rather than negotiable. Widths are honoured either way in the ordinary case — this only changes the two situations where the automatic layout overrules them. Content that cannot wrap narrower than its column (a long unbroken code) stops widening that column and overflows instead, and widths that together exceed the table stop being scaled down to fit, so the table overflows its container. Columns with no width share whatever is left. Reach for it when a width has to hold exactly. It is not needed to make widths work. boolean | false | |
| perPage | number | 0 | |
| currentPage | number | 1 | |
| qaId | Id that can be set for automation selectors. string | "" | |
| modelValue | Use v-model to bind to value of the bulk selected items. unknown[] | unknown |
Slots
${slot}-prelabel
Dynamically generated slot based on the key or slot property in the heading object; renders content before the heading label
<dynamic:name>
No description
Variables
| Name | Type | Description |
|---|---|---|
name | unknown | — |
body
render table rows
Variables
| Name | Type | Description |
|---|---|---|
rows | Array.<object> | The rows currently rendered: sorted, then paginated |
headings | Array.<object> | Resolved column definitions in render order, matching the header |
cell-contents | function |
|
${slot}
Dynamically generated slot based on the key or slot property in the heading object; used to modify the columns display value
Variables
| Name | Type | Description |
|---|---|---|
content | any | Default display value |
row | object | Full row object |
row-index | number | Row index, does not take any pagination into account |
heading-index | number | Column index |
Events
update:model-value
No description
sort
No description
Methods
No methods defined.
Sorting
Sorting is driven entirely by the headings array — one SortableTableHeading per column. Each heading gets a clickable header that sorts on that column's key.
- Only one column sorts at a time. Clicking a header makes it the active column and sorts ascending; clicking the active header again reverses it. Activating another column resets the previous one.
- Set the initial sort with
active: trueon a heading, plusreversed: trueto start descending. If more than one heading is markedactive, the first one wins. With noactiveheading the rows render in the order they were passed. - The
rowsprop is never mutated. Each sort produces a new array and emitssortwith the sorted rows. Re-assigningrowsre-applies the current sort. - Reversing is a straight reversal of the ascending result, so values that sort last ascending (blanks, unranked values) lead when reversed.
- Grouped tables sort inside each group. Pass
groupsand the group order and boundaries stay put — only the rows within each group are reordered. - Totals rows never sort. A group's
totalsrow stays at the bottom of its group and thetotalsprop stays in the<tfoot>, whatever the sort.showGroupHeadingsandtotalsare forwarded to EnTableBasic, which documents them. - The
bodyslot receives the sorted, paged rows. It also passes the resolvedheadingsand thecellContentsformatter, so a hand-rendered<tbody>reflects the current sort and page. - Pagination sorts the full list first, then pages it, so sorting isn't limited to the visible page.
Sort types
The sortType on a heading picks the comparison. Note that sortIcon (numeric, alpha, or omitted for the default arrows) only changes the header icon — it has no effect on the sorting itself.
sortType | Compares | Blank / null values |
|---|---|---|
| omitted | Case-insensitive string compare of the cell value | Sort last |
numeric | The cell value with all non-numeric characters stripped, compared as a number — so "$120,000" sorts as 120000 | Treated as 0 |
date | The cell value passed through new Date() | Sort first |
order | A rank you define per column — see Custom order | Sort last |
bulk-select | Selection order of the bulk-action checkboxes, selected rows first. Requires enableBulkAction; the header renders the select-all checkbox instead of a sort toggle | n/a |
none | Nothing — the column renders as plain, non-clickable header text | n/a |
For anything else, give the heading a compare function and it will be called with the two cell values, like the callback passed to Array.prototype.sort.
When a heading defines more than one of these, the order of precedence is: order → sortType (numeric, date, bulk-select) → compare → default string compare. So order overrides a compare function, but a numeric, date, or bulk-select sortType overrides order.
Custom order
Use order when a column needs to sort by meaning instead of alphabetically — a status column that should read Draft → Active → Pending → Termed, or a coverage tier that should read Employee → Employee + Spouse → Family. Ranks sort lowest first, 0 and negative numbers work as you'd expect, and numeric strings are coerced. sortType: 'order' is optional — defining order is enough — but it documents the intent.
The rank can be declared three ways:
order value | Meaning |
|---|---|
string | The name of another property on each row holding that row's rank, e.g. order: 'statusOrder' with rows like { status: 'Pending', statusOrder: 1 }. Use this when the rank comes down from the server alongside the value. |
object | A map of cell value to rank, e.g. order: { high: 1, medium: 2, low: 3 }. |
array | The values in the order you want them, where the array index is the rank, e.g. order: ['Draft', 'Active', 'Pending', 'Termed']. |
Values that can't be ranked — missing from the map or array, or a row rank that is missing, empty, or not a number — sort last, and tie-break alphabetically among themselves. Rows sharing the same rank keep their original relative order.
Each of the last three columns below declares its rank a different way. Unmapped, unranked, and Waived have no rank, so they sort last in every case.
Custom compare function
For a comparison that doesn't fit any sortType, pass compare. Here the plan column sorts by the length of the plan name.
Column alignment
Column alignment works the same as on EnTableBasic: set class on the heading object to apply a CSS class to both the sortable header and every cell in the column — e.g. class: "text-right" to right-align a currency or numeric column. The demo at the top of this page right-aligns its Date of Birth column exactly this way. See the table guidelines for when to right-align.
Types
SortableTableHeading -
Object| Name | Type | Description |
|---|---|---|
label | string | Display text for the column header. |
srLabel | string | Screen-reader-only name for the column, rendered in addition to |
key | string | Identifier for the location of the data for this column. |
slot | string | The name of the slot created for the data in the cell and the header; defaults to the key unless a value is provided. |
class | string | Applies a CSS class to both the header and the table cell. |
headerClass | string | Applies a CSS class to just the header. |
width | numberstring | Sets the column's width, rendered as a |
renderInTable | boolean | Filters the heading out of the table so it will not display. |
active | boolean | Whether this column's sorting should be active or not. |
reversed | boolean | Whether this column's sorting should be reversed or not. |
isSortable | boolean | Whether this column is sortable. |
sortType | "none""numeric""date""order" | Specify how to sort the data when sorting is used. |
order | CustomOrder | Custom (non-alphabetical) ordering for the column's values. Sorted numerically by rank, lowest first (negatives and 0 supported); values without a rank sort last and tie-break alphabetically. Takes precedence over string sorting and over |
compare | CompareFn | Custom compare function for sorting. |
CompareFn -
function| Name | Type | Description |
|---|---|---|
a | * | — |
b | * | — |