mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
[improvements] Table - exposed active sort options and add an event (#4151)
* exposed sorted options * adds onSort event * clean up
This commit is contained in:
parent
22c87762e4
commit
3af3835e7d
3 changed files with 25 additions and 0 deletions
|
|
@ -322,6 +322,29 @@ export function Table({
|
|||
}
|
||||
);
|
||||
|
||||
const sortOptions = useMemo(() => {
|
||||
if (state?.sortBy?.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const columnName = columns.find((column) => column.id === state?.sortBy?.[0]?.id).accessor;
|
||||
|
||||
return {
|
||||
sortedBy: {
|
||||
column: columnName,
|
||||
direction: state?.sortBy?.[0]?.desc ? 'descending' : 'ascending',
|
||||
},
|
||||
};
|
||||
}, [JSON.stringify(state)]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!sortOptions) {
|
||||
setExposedVariable('sortedBy', null);
|
||||
return;
|
||||
}
|
||||
setExposedVariable('sortedBy', sortOptions.sortedBy).then(() => fireEvent('onSort'));
|
||||
}, [sortOptions]);
|
||||
|
||||
registerAction(
|
||||
'setPage',
|
||||
async function (targetPageIndex) {
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ export const widgets = [
|
|||
onBulkUpdate: { displayName: 'Bulk update' },
|
||||
onPageChanged: { displayName: 'Page changed' },
|
||||
onSearch: { displayName: 'Search' },
|
||||
onSort: { displayName: 'On sorting columns' },
|
||||
onCellValueChanged: { displayName: 'Cell value changed' },
|
||||
onFilterChanged: { displayName: 'Filter changed' },
|
||||
},
|
||||
|
|
|
|||
|
|
@ -512,6 +512,7 @@ export async function onEvent(_ref, eventName, options, mode = 'edit') {
|
|||
'onOpen',
|
||||
'onClose',
|
||||
'onRowClicked',
|
||||
'onSort',
|
||||
'onCellValueChanged',
|
||||
'onFilterChanged',
|
||||
].includes(eventName)
|
||||
|
|
|
|||
Loading…
Reference in a new issue