Skip to content

Commit 8f199d3

Browse files
committed
sync multiple Pagination components
1 parent 97fe831 commit 8f199d3

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/components/Pagination.jsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const Pagination = component$((props) => {
1515

1616
const changePosts = $((e) => {
1717
props.postPerPage.value = e.target.value ;
18+
props.postPerPageSelectedIndex.value = props.postPerPageValues.indexOf(props.postPerPage.value);
1819
})
1920

2021
const changePageNo = $((e) => {
@@ -42,17 +43,10 @@ export const Pagination = component$((props) => {
4243

4344
<div class='post-select'>
4445
<div>Rows per page </div>
45-
<select onInput$={changePosts}>
46-
<option>10</option>
47-
<option>20</option>
48-
<option>50</option>
49-
<option selected>100</option>
50-
<option>200</option>
51-
<option>500</option>
52-
<option>1000</option>
53-
<option>2000</option>
54-
<option>5000</option>
55-
<option>10000</option>
46+
<select bind:value={props.postPerPage}>
47+
{props.postPerPageValues.map(postPerPage => (
48+
<option selected={postPerPage == props.postPerPage.value}>{postPerPage}</option>
49+
))}
5650
</select>
5751
</div>
5852

src/components/table/QwikTable.jsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,29 @@ export const QwikTable = component$((props) => {
3434
);
3535
useStylesScoped$(AppCSS);
3636

37+
const postPerPageValues = [
38+
10,
39+
20,
40+
30,
41+
50,
42+
100,
43+
200,
44+
300,
45+
500,
46+
1000,
47+
2000,
48+
3000,
49+
5000,
50+
10000,
51+
];
52+
53+
const postPerPageDefaultValue = 100;
54+
3755
const sortOrder = useSignal('asc');
3856
//const sortKey = useSignal(props.header[0].key);
3957
const sortKey = useSignal(undefined); // perf: dont sort by default
4058
const pageNo = useSignal(1);
41-
const postPerPage = useSignal(100);
59+
const postPerPage = useSignal(postPerPageDefaultValue);
4260
const totalPosts = useSignal(props.data.length);
4361
const searchBy = useSignal(props.header[0].key);
4462
const searchInp = useSignal('');
@@ -99,6 +117,7 @@ export const QwikTable = component$((props) => {
99117

100118
<Pagination
101119
pageNo={pageNo}
120+
postPerPageValues={postPerPageValues}
102121
postPerPage={postPerPage}
103122
totalPosts={totalPosts}
104123
/>
@@ -117,6 +136,7 @@ export const QwikTable = component$((props) => {
117136

118137
<Pagination
119138
pageNo={pageNo}
139+
postPerPageValues={postPerPageValues}
120140
postPerPage={postPerPage}
121141
totalPosts={totalPosts}
122142
/>

0 commit comments

Comments
 (0)