doo-boilerplate 0.2.12 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doo-boilerplate",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "CLI to scaffold Pila portal frontend projects",
5
5
  "type": "module",
6
6
  "bin": {
@@ -46,10 +46,15 @@ export function DataTable<TData>({ table, columns, isLoading }: DataTableProps<T
46
46
  columnOrder.indexOf(String(over.id))
47
47
  )
48
48
  setColumnOrder(newOrder)
49
- table.setColumnOrder(newOrder)
50
49
  }
51
50
  }
52
51
 
52
+ // Sort headers/cells by local columnOrder so DnD works without wiring
53
+ // onColumnOrderChange in the parent useReactTable config.
54
+ function sortById<T extends { id: string }>(items: T[]): T[] {
55
+ return [...items].sort((a, b) => columnOrder.indexOf(a.id) - columnOrder.indexOf(b.id))
56
+ }
57
+
53
58
  return (
54
59
  <DndContext
55
60
  sensors={sensors}
@@ -68,7 +73,7 @@ export function DataTable<TData>({ table, columns, isLoading }: DataTableProps<T
68
73
  strategy={horizontalListSortingStrategy}
69
74
  >
70
75
  <tr>
71
- {headerGroup.headers.map((header) => (
76
+ {sortById(headerGroup.headers).map((header) => (
72
77
  <SortableHeader key={header.id} header={header} />
73
78
  ))}
74
79
  </tr>
@@ -89,7 +94,7 @@ export function DataTable<TData>({ table, columns, isLoading }: DataTableProps<T
89
94
  ) : table.getRowModel().rows.length ? (
90
95
  table.getRowModel().rows.map((row) => (
91
96
  <TableRow key={row.id} data-state={row.getIsSelected() && 'selected'}>
92
- {row.getVisibleCells().map((cell) => (
97
+ {sortById(row.getVisibleCells()).map((cell) => (
93
98
  <TableCell key={cell.id}>
94
99
  {flexRender(cell.column.columnDef.cell, cell.getContext())}
95
100
  </TableCell>