import { DataTable } from '@uhg-abyss/web/ui/DataTable';import { useDataTable } from '@uhg-abyss/web/hooks/useDataTable';This is a migration guide from V1 DataTable to the new DataTable. DataTable is a complete rewrite of the V1 DataTable component. While this means migrating will require more effort compared to other V2 components, the benefits of the new DataTable are worth it.
Before digging into the details, here are some of the changes and benefits of the new DataTable:
Benefits
Sub-componentization
DataTableis now broken up into sub-components. This will allow for more flexibility and customization.
List of sub-components:
DataTable.DownloadDropdownDataTable.TableDataTable.GlobalFilterDataTable.TableSettingsDropdownDataTable.PaginationDataTable.BulkActionsDropdownDataTable.SlotWrapper
Column filtering
- Filtering can now be achieved at the column level. This means you no longer need to open a modal dialog to filter an individual column. Instead, you can filter directly from the column header.
- There are now two types of column filtering:
'basic'and'advanced'.- Basic filtering provides a
TextInput,SelectInput, or aDateInputdepending on the column type. - Advanced filtering uses a
Popoverthat allows for multiple conditions to be added.- We have also added the ability to use the disjunctive operator (OR) in addition to the conjunctive operator (AND) when applying multiple conditions to a single column.
- Basic filtering provides a
Custom filtering and sorting logic
- Custom global or column filtering and sorting logic can be seamlessly integrated into the
DataTablecomponent. If the built-in logic does not work for your use case, you can simply provide your own functionality.
Editable cells
- Cells within the table can now be made editable, meaning that users can edit the contents of a cell directly within the table.
- These editable cells are able to be a
TextInput,SelectInput, orDateInput, depending on the column type.
- These editable cells are able to be a
Virtualization
- Virtualization is completely built into the table. This allows for a smoother experience when working with very large datasets.
Server-side pagination
- We have completely reworked the server-side API. Instead of using a built in
apiPaginationCallfunction as before, we now provide teams complete control over the API logic.- This allows for a more seamless experience when working with server-side data and gives you full control over the API call(s) and loading state.
- We recommend teams use TanStack Query for server-side data fetching, as much of the
DataTableis built on TanStack libraries, but you are free to use any other library you prefer.
Sticky/pinned columns
- Columns can now be pinned to the left or right side of the table. This allows for a more seamless experience when working with datasets with many columns.
- Pinned columns will always be visible, even when scrolling horizontally.
Drag-and-drop columns
- Columns can now be reordered by dragging and dropping them, just as rows could be reordered in the V1
DataTable.- The ability to reorder rows is still available.
Migrating
As noted above, migrating to the DataTable will require more effort than migrating to other components. After reading through the benefits above, it should be clear why.
Before beginning the migration, we recommend reading through the DataTable documentation to get a better understanding of how the new component works.
Troubleshooting
If you encounter any issues during the migration process, please post your questions, problems, or findings on GitHub Discussions. This will allow all teams to see, respond to, and benefit from shared solutions. If someone has already asked a similar question, consider adding your insights or upvoting the existing discussion rather than creating a duplicate. This helps keep the conversation organized and makes it easier for everyone to find relevant information.
Go to the V2DataTable - Migration Support Discussion
import { DataTable } from '@uhg-abyss/web/ui/DataTable';Quick Overview
The DataTable component now accepts sub-components for better organization and flexibility.
DataTable changes
| V1 Prop | Status | Migration Details |
|---|---|---|
headingLevel | Modified | The |
import { useDataTable } from '@uhg-abyss/web/hooks/useDataTable';Quick Overview
The useDataTable hook has seen significant changes to its API to enhance usability and flexibility. This first section outlines simple prop changes, while further sections focus on more complex changes based on the prop.
useDataTable changes
| V1 Prop | Status | Migration Details |
|---|---|---|
initialColumns | Modified | See |
initialData | Modified | The |
showColumnSort | Removed | Sorting is now disabled by default. Use the |
showGlobalFilter | Removed | Teams will need to use the |
customHeaderSection | Removed | The table is now a sub-component so teams can create their own custom content to be placed above the table. |
showDownloadButton | Removed | Teams will need to use the |
showFilterDataset | Removed | Filtering is now handled through the column header. |
showFullscreenButton | Removed | This is no longer supported. Teams can implement their own fullscreen functionality if needed. |
showSelection | Removed | To enable multi-selection checkboxes, set |
defaultSelectedRows | Removed | To set the default selected rows, use the |
singleSelection | Removed | To enable single-selection set |
bulkActions | Removed | Bulk actions have been moved to the |
individualActions | Removed | Individual row actions have been moved to the |
showPagination | Removed | Teams will need to use the |
pageSizeOptions | Removed | Use the |
defaultPage | Removed | |
enableGroupBy | Removed | |
renderSubComponent | Removed | |
showExpansion | Removed | |
initialGlobalFilter | Removed | Teams now have full control over the global filter state. |
showTableSettings | Removed | Hiding empty columns and changing row height can be achieved through the |
showColumnVisibilityConfig | Removed | Table settings drawer was removed. Column visibility can still be achieved through the |
onColumnVisibilityClose | Removed | Table settings drawer was removed. Column visibility can still be achieved through the |
onColumnVisibilityOpen | Removed | Table settings drawer was removed. Column visibility can still be achieved through the |
reorderRows | Removed | Use the |
onRowOrderChange | Removed | Use the |
uniqueStorageId | Removed | Teams will need to manage their own storage. |
useDataTable.initialColumns prop changes
| V1 Prop | Status | Migration Details |
|---|---|---|
Header | Renamed |
|
Cell | Renamed |
|
Footer | Renamed |
|
accessor | Renamed |
|
canToggleVisibility | Renamed |
|
disableResizing | Renamed |
|
minWidth | Renamed |
|
width | Renamed |
|
maxWidth | Renamed |
|
disableSortBy | Renamed |
|
sortType | Renamed |
|
isHiddenByDefault | Removed | Teams have full control over column visibility. Use |
label | Removed | The |
showColumn | Removed | Teams have full control over column visibility. Use |
hiddenDefaultFilters | Removed | Filtering logic is now handled through the |
customAPIFilters | Removed | Filtering logic is now handled through the |
import { useDownloadCsv } from '@uhg-abyss/web/hooks/useDataTable';import { downloadCsv } from '@uhg-abyss/web/tools/downloadCsv';Quick Overview
The CSV download helper has moved from being provided by the useDataTable hook to a standalone downloadCsv utility. Teams should call the function directly rather than retrieving it from the table hook.
CSV Download changes
| V1 Prop | Status | Migration Details |
|---|---|---|
useDownloadCsv | Removed |
|