2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-07 06:00:57 +00:00

[UI] Fix table column ordering (#9945)

* Fix table column ordering

- Ensure that table columns are always rendererd in the correct order

* Cleanup code

* Adjust col order
This commit is contained in:
Oliver
2025-07-03 13:32:53 +10:00
committed by GitHub
parent ededeeee00
commit 305b253417
2 changed files with 18 additions and 17 deletions

View File

@ -378,19 +378,20 @@ export function InvenTreeTable<T extends Record<string, any>>({
// Ensure that the "actions" column is always at the end of the list // Ensure that the "actions" column is always at the end of the list
// This effect is necessary as sometimes the underlying mantine-datatable columns change // This effect is necessary as sometimes the underlying mantine-datatable columns change
useEffect(() => { useEffect(() => {
const idx: number = tableColumns.columnsOrder.indexOf( // Ensure that the columns are always in the order specified by the columns prop
ACTIONS_COLUMN_ACCESSOR const columnOrder = tableColumns.columnsOrder.slice().sort((a, b) => {
); const idxA = dataColumns.findIndex((col: any) => col.accessor == a);
const idxB = dataColumns.findIndex((col: any) => col.accessor == b);
return idxA - idxB;
});
if (idx >= 0 && idx < tableColumns.columnsOrder.length - 1) { // Update the columns order only if it has changed
// Actions column is not at the end of the list - move it there if (
const newOrder = tableColumns.columnsOrder.filter( JSON.stringify(tableColumns.columnsOrder) != JSON.stringify(columnOrder)
(col) => col != ACTIONS_COLUMN_ACCESSOR ) {
); tableColumns.setColumnsOrder(columnOrder);
newOrder.push(ACTIONS_COLUMN_ACCESSOR);
tableColumns.setColumnsOrder(newOrder);
} }
}, [tableColumns.columnsOrder, tableColumns.setColumnsOrder]); }, [dataColumns, tableColumns.columnsOrder]);
// Reset the pagination state when the search term changes // Reset the pagination state when the search term changes
useEffect(() => { useEffect(() => {

View File

@ -112,12 +112,6 @@ export default function BuildAllocatedStockTable({
sortable: true, sortable: true,
switchable: true switchable: true
}, },
{
accessor: 'quantity',
title: t`Allocated Quantity`,
sortable: true,
switchable: false
},
{ {
accessor: 'serial', accessor: 'serial',
title: t`Serial Number`, title: t`Serial Number`,
@ -137,6 +131,12 @@ export default function BuildAllocatedStockTable({
title: t`Available Quantity`, title: t`Available Quantity`,
render: (record: any) => record?.stock_item_detail?.quantity render: (record: any) => record?.stock_item_detail?.quantity
}, },
{
accessor: 'quantity',
title: t`Allocated Quantity`,
sortable: true,
switchable: false
},
LocationColumn({ LocationColumn({
accessor: 'location_detail', accessor: 'location_detail',
switchable: true, switchable: true,