Skip to content

Commit

Permalink
feat(ktable): add column resize support [khcp-11161] (#2105)
Browse files Browse the repository at this point in the history
Add column resize support to `KTable` for [KHCP-11161](https://konghq.atlassian.net/browse/KHCP-11161).
  • Loading branch information
kaiarrowood authored Apr 4, 2024
1 parent 37356dc commit c448c49
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 88 deletions.
21 changes: 19 additions & 2 deletions docs/components/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ See [the State section](#error) about `hasError`

See [the State section](#loading) about `isLoading`

### resizeColumns

Allow table column width to be resizable. Adjusting a column's width will trigger an `@update:table-preferences` event.

<KTable :fetcher="tableOptionsFetcher" :headers="resizeHeaders" resize-columns />

```html
<KTable :fetcher="fetcher" :headers="headers" resize-columns />
```

### disablePaginationPageJump

Set this to `true` to limit pagination navigation to `previous` / `next` page only.
Expand Down Expand Up @@ -749,7 +759,7 @@ Using a `KPop` inside of a clickable row requires some special handling. Non-cli
<template v-slot:other>
<div>
<KPop title="Cool header">
<KButton>
<KButton appearance="tertiary">
<template #icon>
<KIcon
icon="more"
Expand Down Expand Up @@ -782,7 +792,7 @@ Using a `KPop` inside of a clickable row requires some special handling. Non-cli
<template v-slot:other>
<div>
<KPop title="Cool header">
<KButton>
<KButton appearance="tertiary">
<template #icon>
<KIcon
icon="more"
Expand Down Expand Up @@ -910,6 +920,8 @@ interface TablePreferences {
sortColumnKey?: string
/** The order by which to sort the column, one of `asc` or `desc` */
sortColumnOrder?: 'asc' | 'desc'
/** The customized column widths, if resizing is allowed */
columnWidths?: Record<string, number>
}
```

Expand Down Expand Up @@ -1590,6 +1602,11 @@ export default defineComponent({
{ label: 'Description', key: 'description', sortable: true },
{ label: 'Enabled', key: 'enabled', sortable: false }
],
resizeHeaders: [
{ label: 'Name', key: 'name' },
{ label: 'ID', key: 'id' },
{ label: 'Enabled', key: 'enabled' },
],
tableOptionsHeaders: [
{ label: 'Name', key: 'name' },
{ label: 'ID', key: 'id' },
Expand Down
1 change: 1 addition & 0 deletions sandbox/pages/SandboxTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
:initial-fetcher-params="{
pageSize: 30
}"
resize-columns
>
<template #actions>
<KDropdown>
Expand Down
18 changes: 14 additions & 4 deletions src/components/KTable/KTable.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ describe('KTable', () => {

cy.get('.k-table').should('have.class', 'has-hover')
})

it('renders column resize toggles when resizeColumns is set', () => {
mount(KTable, {
props: {
testMode: 'true',
headers: options.headers,
fetcher: () => { return { data: options.data } },
resizeColumns: true,
},
})

cy.get('.k-table').find('th.resizable').should('be.visible')
cy.get('.resize-handle').should('exist')
})
})

describe('data revalidates and changes as expected', () => {
Expand Down Expand Up @@ -276,7 +290,6 @@ describe('KTable', () => {
fetcher: offsetPaginationFetcher,
isLoading: false,
headers: offsetPaginationHeaders,
offset: true,
},
})

Expand Down Expand Up @@ -570,7 +583,6 @@ describe('KTable', () => {
paginationPageSizes: [10, 15, 20],
hidePaginationWhenOptional: true,
initialFetcherParams: { offset: null },
offset: true,
cacheIdentifier: 'offset-pagination',
},
})
Expand All @@ -590,7 +602,6 @@ describe('KTable', () => {
headers: options.headers,
paginationPageSizes: [10, 15, 20],
hidePaginationWhenOptional: true,
offset: true,
},
})

Expand All @@ -617,7 +628,6 @@ describe('KTable', () => {
headers: options.headers,
paginationPageSizes: [10, 15, 20],
hidePaginationWhenOptional: true,
offset: true,
searchInput: '',
cacheIdentifier: 'search-example',
},
Expand Down
Loading

0 comments on commit c448c49

Please sign in to comment.