Skip to content

Commit 9753dfd

Browse files
Kiarokhjgroth
authored andcommitted
feat(table): add a prop to easily control the pagination's location
You can now render the pagination component on top or at the bottom of the table, using a prop. This was previously an undocumented feature, applicable using a helper class of `has-pagination-on-top`. But now it is more accessible and discoverable feature for the consumer.
1 parent e662a12 commit 9753dfd

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

etc/lime-elements.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ export namespace Components {
733733
"movableColumns": boolean;
734734
"page": number;
735735
"pageSize": number;
736+
"paginationLocation": 'top' | 'bottom';
736737
"selectable": boolean;
737738
"selection": object[];
738739
"sorting": ColumnSorter[];
@@ -1881,6 +1882,7 @@ export namespace JSX {
18811882
"onSort"?: (event: LimelTableCustomEvent<ColumnSorter[]>) => void;
18821883
"page"?: number;
18831884
"pageSize"?: number;
1885+
"paginationLocation"?: 'top' | 'bottom';
18841886
"selectable"?: boolean;
18851887
"selection"?: object[];
18861888
"sorting"?: ColumnSorter[];
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Component, h, Host, State } from '@stencil/core';
2+
import {
3+
Column,
4+
Option,
5+
LimelSelectCustomEvent,
6+
} from '@limetech/lime-elements';
7+
import { data, Bird } from './birds';
8+
import { capitalize } from 'lodash-es';
9+
10+
/**
11+
* Pagination
12+
* By specifying a `pageSize`, you can enable pagination for the table.
13+
*
14+
* Additionally, you can control the location of the pagination controls
15+
* by setting the `paginationLocation` property to either `top` or `bottom`.
16+
*
17+
* @sourceFile birds.ts
18+
*/
19+
@Component({
20+
tag: 'limel-example-table-pagination',
21+
styleUrl: 'table.scss',
22+
shadow: true,
23+
})
24+
export class TablePaginationExample {
25+
@State()
26+
private columns: Array<Column<Bird>> = [
27+
{ title: 'Name', field: 'name' },
28+
{ title: 'Binominal name', field: 'binominalName' },
29+
{ title: 'Nest type', field: 'nest', formatter: capitalize },
30+
{ title: 'Eggs per clutch', field: 'eggs', horizontalAlign: 'right' },
31+
{ title: 'Origin', field: 'origin' },
32+
];
33+
34+
@State()
35+
private paginationLocation: 'top' | 'bottom' = 'bottom';
36+
37+
private paginationLocationOptions: Option[] = [
38+
{ text: 'Top', value: 'top' },
39+
{ text: 'Bottom', value: 'bottom' },
40+
];
41+
42+
private pageSize = 5;
43+
44+
render() {
45+
return (
46+
<Host>
47+
<limel-table
48+
data={data}
49+
columns={this.columns}
50+
pageSize={this.pageSize}
51+
paginationLocation={this.paginationLocation}
52+
/>
53+
<limel-example-controls>
54+
<limel-select
55+
label="Pagination location"
56+
value={this.getSelectedPaginationLocation()}
57+
options={this.paginationLocationOptions}
58+
onChange={this.handlePaginationLocationChange}
59+
/>
60+
</limel-example-controls>
61+
</Host>
62+
);
63+
}
64+
65+
private getSelectedPaginationLocation = (): Option => {
66+
return this.paginationLocationOptions.find(
67+
(option) => option.value === this.paginationLocation
68+
);
69+
};
70+
71+
private handlePaginationLocationChange = (
72+
event: LimelSelectCustomEvent<Option>
73+
) => {
74+
this.paginationLocation = event.detail.value as 'top' | 'bottom';
75+
};
76+
}

src/components/table/table.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const FIRST_PAGE = 1;
4646
* @exampleComponent limel-example-table-header-menu
4747
* @exampleComponent limel-example-table-movable-columns
4848
* @exampleComponent limel-example-table-sorting-disabled
49+
* @exampleComponent limel-example-table-pagination
4950
* @exampleComponent limel-example-table-local
5051
* @exampleComponent limel-example-table-remote
5152
* @exampleComponent limel-example-table-activate-row
@@ -179,6 +180,14 @@ export class Table {
179180
@Prop({ reflect: true })
180181
public language: Languages = 'en';
181182

183+
/**
184+
* Location of the pagination controls.
185+
* - `top`: Display pagination controls at the top of the table
186+
* - `bottom`: Display pagination controls at the bottom of the table (default)
187+
*/
188+
@Prop({ reflect: true })
189+
public paginationLocation: 'top' | 'bottom' = 'bottom';
190+
182191
/**
183192
* Emitted when `mode` is `remote` and the table is loading new data. The
184193
* consumer is responsible for giving the table new data
@@ -863,6 +872,7 @@ export class Table {
863872
<Host
864873
class={{
865874
'has-low-density': this.layout === 'lowDensity',
875+
'has-pagination-on-top': this.paginationLocation === 'top',
866876
}}
867877
>
868878
<div

0 commit comments

Comments
 (0)