@dataloop-ai/components 0.16.15 → 0.16.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -408,7 +408,17 @@
|
|
|
408
408
|
</div>
|
|
409
409
|
|
|
410
410
|
<div
|
|
411
|
-
v-if="
|
|
411
|
+
v-if="hasPaginationSlot"
|
|
412
|
+
class="dl-table__control"
|
|
413
|
+
>
|
|
414
|
+
<slot
|
|
415
|
+
v-bind="marginalsScope"
|
|
416
|
+
name="pagination"
|
|
417
|
+
/>
|
|
418
|
+
</div>
|
|
419
|
+
|
|
420
|
+
<div
|
|
421
|
+
v-else-if="!hideBottom || hideNoData"
|
|
412
422
|
:class="bottomClasses"
|
|
413
423
|
>
|
|
414
424
|
<div class="dl-table__control">
|
|
@@ -620,12 +630,7 @@ export default defineComponent({
|
|
|
620
630
|
const virtScrollRef = ref(null)
|
|
621
631
|
const hasVirtScroll = computed(() => props.virtualScroll === true)
|
|
622
632
|
|
|
623
|
-
const {
|
|
624
|
-
hasClickEvent,
|
|
625
|
-
hasDblClickEvent,
|
|
626
|
-
hasContextMenuEvent,
|
|
627
|
-
hasAnyAction
|
|
628
|
-
} = useTableActions(props)
|
|
633
|
+
const { hasAnyAction } = useTableActions(props) // todo: does not work
|
|
629
634
|
|
|
630
635
|
const getRowKey = computed(() =>
|
|
631
636
|
typeof props.rowKey === 'function'
|
|
@@ -636,6 +641,8 @@ export default defineComponent({
|
|
|
636
641
|
// table slots
|
|
637
642
|
const hasSlotByName = (name: string) => !!slots[name]
|
|
638
643
|
|
|
644
|
+
const hasPaginationSlot = computed(() => hasSlotByName('pagination'))
|
|
645
|
+
|
|
639
646
|
const hasTopSlots = computed(
|
|
640
647
|
() =>
|
|
641
648
|
!!slots['top'] ||
|
|
@@ -999,7 +1006,11 @@ export default defineComponent({
|
|
|
999
1006
|
isFirstPage,
|
|
1000
1007
|
isLastPage,
|
|
1001
1008
|
pagesNumber,
|
|
1002
|
-
computedRowsNumber
|
|
1009
|
+
computedRowsNumber,
|
|
1010
|
+
firstPage,
|
|
1011
|
+
prevPage,
|
|
1012
|
+
nextPage,
|
|
1013
|
+
lastPage
|
|
1003
1014
|
} = useTablePagination(
|
|
1004
1015
|
vm,
|
|
1005
1016
|
computedPagination,
|
|
@@ -1048,7 +1059,11 @@ export default defineComponent({
|
|
|
1048
1059
|
pagination: paginationState.value,
|
|
1049
1060
|
pagesNumber: pagesNumber.value,
|
|
1050
1061
|
isFirstPage: isFirstPage.value,
|
|
1051
|
-
isLastPage: isLastPage.value
|
|
1062
|
+
isLastPage: isLastPage.value,
|
|
1063
|
+
firstPage,
|
|
1064
|
+
prevPage,
|
|
1065
|
+
nextPage,
|
|
1066
|
+
lastPage
|
|
1052
1067
|
}))
|
|
1053
1068
|
|
|
1054
1069
|
function getCellValue(
|
|
@@ -1110,9 +1125,7 @@ export default defineComponent({
|
|
|
1110
1125
|
row: DlTableRow,
|
|
1111
1126
|
pageIndex: number
|
|
1112
1127
|
) => {
|
|
1113
|
-
|
|
1114
|
-
emit('row-click', evt, row, pageIndex)
|
|
1115
|
-
}
|
|
1128
|
+
emit('row-click', evt, row, pageIndex)
|
|
1116
1129
|
}
|
|
1117
1130
|
|
|
1118
1131
|
const onTrDblClick = (
|
|
@@ -1120,9 +1133,7 @@ export default defineComponent({
|
|
|
1120
1133
|
row: DlTableRow,
|
|
1121
1134
|
pageIndex: number
|
|
1122
1135
|
) => {
|
|
1123
|
-
|
|
1124
|
-
emit('row-dblclick', evt, row, pageIndex)
|
|
1125
|
-
}
|
|
1136
|
+
emit('row-dblclick', evt, row, pageIndex)
|
|
1126
1137
|
}
|
|
1127
1138
|
|
|
1128
1139
|
const onTrContextMenu = (
|
|
@@ -1130,9 +1141,7 @@ export default defineComponent({
|
|
|
1130
1141
|
row: DlTableRow,
|
|
1131
1142
|
pageIndex: number
|
|
1132
1143
|
) => {
|
|
1133
|
-
|
|
1134
|
-
emit('row-contextmenu', evt, row, pageIndex)
|
|
1135
|
-
}
|
|
1144
|
+
emit('row-contextmenu', evt, row, pageIndex)
|
|
1136
1145
|
}
|
|
1137
1146
|
|
|
1138
1147
|
function injectBodyCommonScope(data: Record<string, any>) {
|
|
@@ -1210,7 +1219,11 @@ export default defineComponent({
|
|
|
1210
1219
|
resetVirtualScroll,
|
|
1211
1220
|
scrollTo,
|
|
1212
1221
|
setExpanded,
|
|
1213
|
-
sort
|
|
1222
|
+
sort,
|
|
1223
|
+
firstPage,
|
|
1224
|
+
prevPage,
|
|
1225
|
+
nextPage,
|
|
1226
|
+
lastPage
|
|
1214
1227
|
})
|
|
1215
1228
|
|
|
1216
1229
|
return {
|
|
@@ -1258,7 +1271,8 @@ export default defineComponent({
|
|
|
1258
1271
|
displayPagination,
|
|
1259
1272
|
onTrClick,
|
|
1260
1273
|
onTrDblClick,
|
|
1261
|
-
onTrContextMenu
|
|
1274
|
+
onTrContextMenu,
|
|
1275
|
+
hasPaginationSlot
|
|
1262
1276
|
}
|
|
1263
1277
|
}
|
|
1264
1278
|
})
|
|
@@ -80,6 +80,14 @@ export function useTablePaginationState(
|
|
|
80
80
|
)
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
+
watch(
|
|
84
|
+
() => props.pagination,
|
|
85
|
+
(pag) => {
|
|
86
|
+
innerPagination.value = Object.assign(innerPagination.value, pag)
|
|
87
|
+
},
|
|
88
|
+
{ deep: true }
|
|
89
|
+
)
|
|
90
|
+
|
|
83
91
|
const computedPagination = computed(() => {
|
|
84
92
|
const pag =
|
|
85
93
|
props['onUpdate:pagination'] !== void 0
|
|
@@ -175,6 +183,31 @@ export function useTablePagination(
|
|
|
175
183
|
: computedPagination.value.page >= pagesNumber.value
|
|
176
184
|
)
|
|
177
185
|
|
|
186
|
+
function firstPage() {
|
|
187
|
+
setPagination({ page: 1 })
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function prevPage() {
|
|
191
|
+
const { page } = computedPagination.value
|
|
192
|
+
if (page > 1) {
|
|
193
|
+
setPagination({ page: page - 1 })
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function nextPage() {
|
|
198
|
+
const { page, rowsPerPage } = computedPagination.value
|
|
199
|
+
if (
|
|
200
|
+
lastRowIndex.value > 0 &&
|
|
201
|
+
page * rowsPerPage < computedRowsNumber.value
|
|
202
|
+
) {
|
|
203
|
+
setPagination({ page: page + 1 })
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function lastPage() {
|
|
208
|
+
setPagination({ page: pagesNumber.value })
|
|
209
|
+
}
|
|
210
|
+
|
|
178
211
|
watch(pagesNumber, (lastPage, oldLastPage) => {
|
|
179
212
|
if (lastPage === oldLastPage) {
|
|
180
213
|
return
|
|
@@ -198,6 +231,10 @@ export function useTablePagination(
|
|
|
198
231
|
isFirstPage,
|
|
199
232
|
isLastPage,
|
|
200
233
|
pagesNumber,
|
|
201
|
-
computedRowsNumber
|
|
234
|
+
computedRowsNumber,
|
|
235
|
+
firstPage,
|
|
236
|
+
prevPage,
|
|
237
|
+
nextPage,
|
|
238
|
+
lastPage
|
|
202
239
|
}
|
|
203
240
|
}
|
package/src/demo/DlTableDemo.vue
CHANGED
|
@@ -115,13 +115,119 @@
|
|
|
115
115
|
@row-click="log"
|
|
116
116
|
@update:selected="updateSeleted"
|
|
117
117
|
/>
|
|
118
|
+
|
|
119
|
+
<div style="margin-top: 100px">
|
|
120
|
+
<DlTable
|
|
121
|
+
:selected="selected"
|
|
122
|
+
:separator="separator"
|
|
123
|
+
:columns="columns"
|
|
124
|
+
:bordered="bordered"
|
|
125
|
+
:draggable="draggable"
|
|
126
|
+
:pagination="pagination"
|
|
127
|
+
:dense="dense"
|
|
128
|
+
class="sticky-header"
|
|
129
|
+
:filter="filter"
|
|
130
|
+
:selection="selection"
|
|
131
|
+
:loading="loading"
|
|
132
|
+
:rows="tableRows"
|
|
133
|
+
:resizable="resizable"
|
|
134
|
+
row-key="name"
|
|
135
|
+
color="dl-color-secondary"
|
|
136
|
+
title="Table Title"
|
|
137
|
+
:virtual-scroll="vScroll"
|
|
138
|
+
style="height: 500px"
|
|
139
|
+
:rows-per-page-options="rowsPerPageOptions"
|
|
140
|
+
hide-bottom
|
|
141
|
+
@row-click="log"
|
|
142
|
+
@update:selected="updateSeleted"
|
|
143
|
+
>
|
|
144
|
+
<template #pagination="scope">
|
|
145
|
+
<dl-button
|
|
146
|
+
v-if="scope.pagesNumber > 2"
|
|
147
|
+
icon="icon-dl-first-page"
|
|
148
|
+
color="dl-color-secondary"
|
|
149
|
+
flat
|
|
150
|
+
:disabled="scope.isFirstPage"
|
|
151
|
+
@click="scope.firstPage"
|
|
152
|
+
/>
|
|
153
|
+
|
|
154
|
+
<dl-button
|
|
155
|
+
icon="icon-dl-left-chevron"
|
|
156
|
+
color="dl-color-secondary"
|
|
157
|
+
flat
|
|
158
|
+
:disabled="scope.isFirstPage"
|
|
159
|
+
@click="scope.prevPage"
|
|
160
|
+
/>
|
|
161
|
+
|
|
162
|
+
<dl-button
|
|
163
|
+
icon="icon-dl-right-chevron"
|
|
164
|
+
color="dl-color-secondary"
|
|
165
|
+
flat
|
|
166
|
+
:disabled="scope.isLastPage"
|
|
167
|
+
@click="scope.nextPage"
|
|
168
|
+
/>
|
|
169
|
+
|
|
170
|
+
<dl-button
|
|
171
|
+
v-if="scope.pagesNumber > 2"
|
|
172
|
+
icon="icon-dl-last-page"
|
|
173
|
+
color="dl-color-secondary"
|
|
174
|
+
flat
|
|
175
|
+
:disabled="scope.isLastPage"
|
|
176
|
+
@click="scope.lastPage"
|
|
177
|
+
/>
|
|
178
|
+
</template>
|
|
179
|
+
</DlTable>
|
|
180
|
+
|
|
181
|
+
<div>
|
|
182
|
+
<p>Custom pagination outside pagination slot</p>
|
|
183
|
+
<dl-button
|
|
184
|
+
v-if="pagesNumber > 2"
|
|
185
|
+
icon="icon-dl-first-page"
|
|
186
|
+
color="dl-color-secondary"
|
|
187
|
+
flat
|
|
188
|
+
:disabled="isFirstPage"
|
|
189
|
+
@click="firstPage"
|
|
190
|
+
/>
|
|
191
|
+
|
|
192
|
+
<dl-button
|
|
193
|
+
icon="icon-dl-left-chevron"
|
|
194
|
+
color="dl-color-secondary"
|
|
195
|
+
flat
|
|
196
|
+
:disabled="isFirstPage"
|
|
197
|
+
@click="prevPage"
|
|
198
|
+
/>
|
|
199
|
+
|
|
200
|
+
<dl-button
|
|
201
|
+
icon="icon-dl-right-chevron"
|
|
202
|
+
color="dl-color-secondary"
|
|
203
|
+
flat
|
|
204
|
+
:disabled="isLastPage"
|
|
205
|
+
@click="nextPage"
|
|
206
|
+
/>
|
|
207
|
+
|
|
208
|
+
<dl-button
|
|
209
|
+
v-if="pagesNumber > 2"
|
|
210
|
+
icon="icon-dl-last-page"
|
|
211
|
+
color="dl-color-secondary"
|
|
212
|
+
flat
|
|
213
|
+
:disabled="isLastPage"
|
|
214
|
+
@click="lastPage"
|
|
215
|
+
/>
|
|
216
|
+
</div>
|
|
217
|
+
</div>
|
|
118
218
|
</div>
|
|
119
219
|
</div>
|
|
120
220
|
</template>
|
|
121
221
|
|
|
122
222
|
<script lang="ts">
|
|
123
|
-
import {
|
|
124
|
-
|
|
223
|
+
import {
|
|
224
|
+
DlTable,
|
|
225
|
+
DlOptionGroup,
|
|
226
|
+
DlSwitch,
|
|
227
|
+
DlInput,
|
|
228
|
+
DlButton
|
|
229
|
+
} from '../components'
|
|
230
|
+
import { defineComponent, ref, computed, watch } from 'vue-demi'
|
|
125
231
|
import { times } from 'lodash'
|
|
126
232
|
|
|
127
233
|
const columns = [
|
|
@@ -280,7 +386,89 @@ export default defineComponent({
|
|
|
280
386
|
DlTable,
|
|
281
387
|
DlSwitch,
|
|
282
388
|
DlOptionGroup,
|
|
283
|
-
DlInput
|
|
389
|
+
DlInput,
|
|
390
|
+
DlButton
|
|
391
|
+
},
|
|
392
|
+
setup() {
|
|
393
|
+
const pagination = ref({
|
|
394
|
+
sortBy: 'desc',
|
|
395
|
+
descending: false,
|
|
396
|
+
page: 2,
|
|
397
|
+
rowsPerPage: 3
|
|
398
|
+
// rowsNumber: xx if getting data from a server
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
const pagesNumber = computed(() => {
|
|
402
|
+
return Math.ceil(rows.length / pagination.value.rowsPerPage)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
function fixPagination(p: typeof pagination.value) {
|
|
406
|
+
if (p.page < 1) {
|
|
407
|
+
p.page = 1
|
|
408
|
+
}
|
|
409
|
+
if (p.rowsPerPage !== void 0 && p.rowsPerPage < 1) {
|
|
410
|
+
p.rowsPerPage = 0
|
|
411
|
+
}
|
|
412
|
+
return p
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const lastRowIndex = computed(() => {
|
|
416
|
+
const { page, rowsPerPage } = pagination.value
|
|
417
|
+
return page * rowsPerPage
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
const setPagination = (val: Partial<typeof pagination.value>) => {
|
|
421
|
+
pagination.value = fixPagination({
|
|
422
|
+
...pagination.value,
|
|
423
|
+
...val
|
|
424
|
+
})
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function firstPage() {
|
|
428
|
+
setPagination({ page: 1 })
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function prevPage() {
|
|
432
|
+
const { page } = pagination.value
|
|
433
|
+
if (page > 1) {
|
|
434
|
+
setPagination({ page: page - 1 })
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const tableRows = ref(rows)
|
|
439
|
+
|
|
440
|
+
function nextPage() {
|
|
441
|
+
const { page, rowsPerPage } = pagination.value
|
|
442
|
+
|
|
443
|
+
if (
|
|
444
|
+
lastRowIndex.value > 0 &&
|
|
445
|
+
page * rowsPerPage < tableRows.value.length
|
|
446
|
+
) {
|
|
447
|
+
setPagination({ page: page + 1 })
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const isLastPage = computed(
|
|
452
|
+
() => pagination.value.page >= pagesNumber.value
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
const isFirstPage = computed(() => pagination.value.page === 1)
|
|
456
|
+
|
|
457
|
+
function lastPage() {
|
|
458
|
+
setPagination({ page: pagesNumber.value })
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return {
|
|
462
|
+
pagination,
|
|
463
|
+
pagesNumber,
|
|
464
|
+
tableRows,
|
|
465
|
+
firstPage,
|
|
466
|
+
lastPage,
|
|
467
|
+
nextPage,
|
|
468
|
+
prevPage,
|
|
469
|
+
isLastPage,
|
|
470
|
+
isFirstPage
|
|
471
|
+
}
|
|
284
472
|
},
|
|
285
473
|
data() {
|
|
286
474
|
return {
|