@@ -10,16 +10,19 @@ export type { DsfrTableProps }
1010const props = withDefaults (defineProps <DsfrTableProps >(), {
1111 headers : () => [],
1212 rows : () => [],
13- defaultCurrentPage : 1 ,
14- defaultOptionSelected : 10 ,
13+ currentPage : 1 ,
14+ resultsDisplayed : 10 ,
1515})
1616
17+ // Permet aux utilisateurs d'utiliser une fonction afin de charger des résultats au changement de page
18+ const emit = defineEmits <{(event : ' update:currentPage' ): void }>()
19+
1720const getRowData = (row : (DsfrTableRowProps | string [])) => {
1821 return Array .isArray (row ) ? row : row .rowData
1922}
2023
21- const currentPage = ref (props .defaultCurrentPage )
22- const optionSelected = ref (props .defaultOptionSelected )
24+ const currentPage = ref (props .currentPage )
25+ const optionSelected = ref (props .resultsDisplayed )
2326const pageCount = ref (props .rows .length > optionSelected .value ? Math .ceil (props .rows .length / optionSelected .value ) : 1 )
2427const paginationOptions = [5 , 10 , 25 , 50 , 100 ]
2528const returnLowestLimit = () => currentPage .value * optionSelected .value - optionSelected .value
@@ -37,18 +40,26 @@ const truncatedResults = computed(() => {
3740 return props .rows
3841})
3942
40- const goFirstPage = () => { currentPage .value = 1 }
43+ const goFirstPage = () => {
44+ currentPage .value = 1
45+ emit (' update:currentPage' )
46+ }
4147const goPreviousPage = () => {
4248 if (currentPage .value > 1 ) {
4349 currentPage .value -= 1
50+ emit (' update:currentPage' )
4451 }
4552}
4653const goNextPage = () => {
4754 if (currentPage .value < pageCount .value ) {
4855 currentPage .value += 1
56+ emit (' update:currentPage' )
4957 }
5058}
51- const goLastPage = () => { currentPage .value = pageCount .value }
59+ const goLastPage = () => {
60+ currentPage .value = pageCount .value
61+ emit (' update:currentPage' )
62+ }
5263 </script >
5364
5465<template >
@@ -89,6 +100,7 @@ const goLastPage = () => { currentPage.value = pageCount.value }
89100 <span >Résultats par page : </span >
90101 <select
91102 v-model =" optionSelected"
103+ @change =" emit('update:currentPage')"
92104 >
93105 <option
94106 v-for =" (option, idx) in paginationOptions"
@@ -108,11 +120,11 @@ const goLastPage = () => { currentPage.value = pageCount.value }
108120 @click =" goFirstPage()"
109121 />
110122 <button
111- class =" fr-icon-arrow-left-s-line-double "
123+ class =" fr-icon-arrow-left-s-line"
112124 @click =" goPreviousPage()"
113125 />
114126 <button
115- class =" fr-icon-arrow-right-s-line-double "
127+ class =" fr-icon-arrow-right-s-line"
116128 @click =" goNextPage()"
117129 />
118130 <button
0 commit comments