11<script lang="ts" setup>
2- import { ref , watch , computed , onMounted } from ' vue'
2+ import { ref , watch } from ' vue'
33import DsfrTableRow , { type DsfrTableRowProps } from ' ./DsfrTableRow.vue'
44import DsfrTableHeaders from ' ./DsfrTableHeaders.vue'
55import { type DsfrTableHeaderProps } from ' ./DsfrTableHeader.vue'
@@ -10,19 +10,23 @@ const props = withDefaults(defineProps<{
1010 rows? : (DsfrTableRowProps | string )[]
1111 noCaption? : boolean
1212 pagination? : boolean
13+ defaultCurrentPage? : number
14+ defaultOptionSelected? : number
1315}>(), {
1416 title: undefined ,
1517 headers : () => [],
1618 rows : () => [],
19+ defaultCurrentPage: 1 ,
20+ defaultOptionSelected: 10 ,
1721})
1822
1923const getRowData = (row : (DsfrTableRowProps | string | ({component: string } & Record <string , any >))) => {
2024 // @ts-ignore TODO: find a way to improve types here
2125 return row .rowData || row
2226}
2327
24- const currentPage = ref (1 )
25- const optionSelected = ref (10 )
28+ const currentPage = ref (props . defaultCurrentPage )
29+ const optionSelected = ref (props . defaultOptionSelected )
2630const pageCount = ref (props .rows .length > optionSelected .value ? Math .ceil (props .rows .length / optionSelected .value ) : 1 )
2731const paginationOptions = [5 , 10 , 25 , 50 , 100 ]
2832const returnLowestLimit = () => currentPage .value * optionSelected .value - optionSelected .value
@@ -39,9 +43,17 @@ watch(() => currentPage.value, (newVal, OldVal) => {
3943})
4044
4145const goFirstPage = () => { currentPage .value = 1 }
42- const goPreviousPage = () => { currentPage .value > 1 ? currentPage .value -= 1 : currentPage .value }
43- const goNextPage = () => { currentPage .value < pageCount .value ? currentPage .value += 1 : currentPage .value }
44- const goLastPage = () => { currentPage .value = pageCount .value }
46+ const goPreviousPage = () => {
47+ if (currentPage .value > 1 ) {
48+ currentPage .value -= 1
49+ }
50+ }
51+ const goNextPage = () => {
52+ if (currentPage .value < pageCount .value ) {
53+ currentPage .value += 1
54+ }
55+ }
56+ const goLastPage = () => { currentPage .value = pageCount .value }
4557
4658 </script >
4759
@@ -87,17 +99,20 @@ const goLastPage = () => { currentPage.value = pageCount.value }
8799 <option
88100 v-for =" (option, idx) in paginationOptions"
89101 :key =" idx"
90- :value =" option" >
102+ :value =" option"
103+ >
91104 {{ option }}
92105 </option >
93106 </select >
94107 </div >
95- <div class =" flex ml-1" ><span class =" self-center" >Page {{ currentPage }} sur {{ pageCount }}</span ></div >
108+ <div class =" flex ml-1" >
109+ <span class =" self-center" >Page {{ currentPage }} sur {{ pageCount }}</span >
110+ </div >
96111 <div class =" flex ml-1" >
97112 <button
98113 class =" fr-icon-arrow-left-s-first-line"
99114 @click =" goFirstPage()"
100- />
115+ />
101116 <button
102117 class =" fr-icon-arrow-left-s-line-double"
103118 @click =" goPreviousPage()"
0 commit comments