Skip to content

Commit c46f49b

Browse files
committed
feat: ✨ Test amélioration de la pagination de tableau
1 parent b8b7c1d commit c46f49b

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

src/components/DsfrTable/DsfrTable.stories.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ export default {
4444
action: 'clicked on row',
4545
description: 'Fonction pour montrer le clic sur une ligne (Ici seulement la 2e ligne)',
4646
},
47-
defaultCurrentPage: {
47+
currentPage: {
4848
control: 'number',
4949
description: 'Le numéro de la page dans la pagination',
5050
},
51-
defaultOptionSelected: {
51+
resultsDisplayed: {
5252
control: 'number',
53-
description: 'La sélection du nombre d\'enregistrements par page',
53+
description: 'La sélection du nombre d\'enregistrements affichés par page',
54+
},
55+
'update:currentPage': {
56+
control: 'event',
57+
description: 'Event se déclenchant au changement de page, laissant la liberté à l\'utilisateur de charger son contenu au fur et à mesure',
5458
},
5559
},
5660
}
@@ -253,8 +257,8 @@ const rows = [
253257
]
254258
const noCaption = false
255259
const pagination = true
256-
const defaultCurrentPage = 2
257-
const defaultOptionSelected = 5
260+
const currentPage = 2
261+
const resultsDisplayed = 5
258262

259263
export const TableauEntier = (args) => ({
260264
components: {
@@ -280,8 +284,8 @@ export const TableauEntier = (args) => ({
280284
:rows="rows"
281285
:no-caption="noCaption"
282286
:pagination="pagination"
283-
:defaultCurrentPage="defaultCurrentPage"
284-
:defaultOptionSelected="defaultOptionSelected"
287+
:currentPage="currentPage"
288+
:resultsDisplayed="resultsDisplayed"
285289
/>
286290
`,
287291

@@ -292,6 +296,6 @@ TableauEntier.args = {
292296
rows,
293297
noCaption,
294298
pagination,
295-
defaultCurrentPage,
296-
defaultOptionSelected,
299+
currentPage,
300+
resultsDisplayed,
297301
}

src/components/DsfrTable/DsfrTable.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ export type DsfrTableProps = {
2626
rows?:(DsfrTableRowProps | string[])[]
2727
noCaption?: boolean
2828
pagination?: boolean
29-
defaultCurrentPage?: number
30-
defaultOptionSelected?: number
29+
currentPage?: number
30+
resultsDisplayed?: number
3131
}

src/components/DsfrTable/DsfrTable.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ export type { DsfrTableProps }
1010
const 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+
1720
const 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)
2326
const pageCount = ref(props.rows.length > optionSelected.value ? Math.ceil(props.rows.length / optionSelected.value) : 1)
2427
const paginationOptions = [5, 10, 25, 50, 100]
2528
const 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+
}
4147
const goPreviousPage = () => {
4248
if (currentPage.value > 1) {
4349
currentPage.value -= 1
50+
emit('update:currentPage')
4451
}
4552
}
4653
const 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

Comments
 (0)