Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ktable): add column resize support [khcp-11161] #2105

Merged
merged 20 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading