Migrating from UITable to HighRise DataTable
This guide will help you migrate from the ghl-ui Table component to the new HighRise DataTable component.
Component Implementation Changes
Import Changes
diff
- import { UITable } from '@gohighlevel/ghl-ui'
+ import { HLDataTable,HLDataTableWrapper } from '@platform-ui/highrise'Breaking Changes
The following architectural changes have been made:
columnsprop:Old New Description keyid, accessorKeyfor column uniqueness titleheadercolumn header rendercellFormattercell formatter function, rowis the row data.dataprop remains the sameenableTextSearchprop:Old New Description enableTextSearch:show-header="true" :show-global-search="true"if enableTextSearchprop is true or prop is not providedcheckedRowKeysprop:Old New Description checkedRowKeysselectedRowsselected rows array @update:searchTextevent:Old New Description @update:searchText@update:global-filterglobal filter event #paginationslot:- Old: Used
#paginationslot - New: Uses
#footerslot withHLPaginationcomponent inHLDataTableWrapperwithfooterslot
- Old: Used
emptyslot:- Old: Used
emptyslot - New: Uses
no-dataslot withHLEmptycomponent insideHLDataTable
- Old: Used
Examples
Basic DataTable Types
diff
- const columns = [
- {
- key: 'name',
- title: 'Name',
- render: (row) => row.name,
- },
- {
- key: 'email',
- title: h('span', { class: 'text-gray-500' }, 'Email'),
- render: (row) => row.email,
- },
- ]
+ const tableInstance = ref(null)
+ const columns = [
+ {
+ id: 'name',
+ header: 'Name',
+ accessorKey: 'name', // this is required for the table to work, key is now accessorKey
+ cellFormatter: (rowData) => rowData.row.original.name,
+ },
+ {
+ id: 'email',
+ header: () => h('span', { class: 'text-gray-500' }, 'Email'),
+ accessorKey: 'email', // this is required for the table to work, key is now accessorKey
+ cellFormatter: (rowData) => rowData.row.original.email,
+ },
+ ]
- <UITable :columns="columns" :data="data" />
+ <HLDataTableWrapper :responsive-column-width="true" max-width="100%">
+ <HLDataTable ref="tableInstance" :columns="columns" :data="data" row-height="auto" />
+ </HLDataTableWrapper>INFO
- in
columnsprop,titleis just replaced withheader, there is no other change, if there ish()function then map it like()=>h() renderis replaced withcellFormatterand param isrowDatawhich is an object and should mappedrowData.row.original
With enableTextSearch
diff
- <UITable :columns="columns" :data="data" :enableTextSearch="true" @update:searchText="updateSearchText" />
+ <HLDataTableWrapper :show-header="true" :show-global-search="true" @update:global-filter="updateSearchText" :responsive-column-width="true" max-width="100%">
+ <HLDataTable ref="tableInstance" :columns="columns" :data="data" row-height="auto" />
+ </HLDataTableWrapper>With Pagination
diff
- <UITable :columns="columns" :data="data" :showSizePicker="true" :pageSizes="[10, 20, 30, 40]" :pageSize="10" :pageSlot="9" />
+ <HLDataTableWrapper :show-header="true" :show-global-search="true" @update:global-filter="updateSearchText" :responsive-column-width="true" max-width="100%">
+ <template #footer>
+ <HLPagination :show-per-page-drop-down="true" :per-page-dropdown-options="[{key: 10, label: '10'}, {key: 20, label: '20'}, {key: 30, label: '30'}, {key: 40, label: '40'}]"
+ :item-count="tableInstance.table?.getFilteredRowModel().rows.length"
+ :per-page="tableInstance.table?.getState().pagination.pageSize"
+ :show-current-range="false"
+ :current-page="tableInstance.table?.getState().pagination.pageIndex + 1"
+ @update:per-page="tableInstance.table?.setPageSize"
+ @update:page="page => {tableInstance.table?.setPageIndex(page - 1)}"
+ />
+ </template>
+ <HLDataTable ref="tableInstance" :columns="columns" :data="data" row-height="auto" />
+ </HLDataTableWrapper>WARNING
- Always add
headerslot forHLDataTableWrapperandHLPaginationcomponent should be insidefooterslot forHLDataTableWrapper HLPaginationcomponent should be insidefooterslot forHLDataTableWrapper
With Empty slot
diff
- <UITable :columns="columns" :data="data">
- <template #empty>
- <UIEmpty />
- </template>
- </UITable>
+ <HLDataTableWrapper :responsive-column-width="true" max-width="100%">
+ <HLDataTable ref="tableInstance" :columns="columns" :data="data" row-height="auto">
+ <template #no-data>
+ <HLEmpty />
+ </template>
+ </HLDataTable>
+ </HLDataTableWrapper>INFO
emptyslot is replaced withno-dataslotHLEmptycomponent is used to show the empty state insideHLDataTable