@dataloop-ai/components 0.16.16 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.16.16",
3
+ "version": "0.16.17",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -408,7 +408,17 @@
408
408
  </div>
409
409
 
410
410
  <div
411
- v-if="!hideBottom || hideNoData"
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">
@@ -631,6 +641,8 @@ export default defineComponent({
631
641
  // table slots
632
642
  const hasSlotByName = (name: string) => !!slots[name]
633
643
 
644
+ const hasPaginationSlot = computed(() => hasSlotByName('pagination'))
645
+
634
646
  const hasTopSlots = computed(
635
647
  () =>
636
648
  !!slots['top'] ||
@@ -994,7 +1006,11 @@ export default defineComponent({
994
1006
  isFirstPage,
995
1007
  isLastPage,
996
1008
  pagesNumber,
997
- computedRowsNumber
1009
+ computedRowsNumber,
1010
+ firstPage,
1011
+ prevPage,
1012
+ nextPage,
1013
+ lastPage
998
1014
  } = useTablePagination(
999
1015
  vm,
1000
1016
  computedPagination,
@@ -1043,7 +1059,11 @@ export default defineComponent({
1043
1059
  pagination: paginationState.value,
1044
1060
  pagesNumber: pagesNumber.value,
1045
1061
  isFirstPage: isFirstPage.value,
1046
- isLastPage: isLastPage.value
1062
+ isLastPage: isLastPage.value,
1063
+ firstPage,
1064
+ prevPage,
1065
+ nextPage,
1066
+ lastPage
1047
1067
  }))
1048
1068
 
1049
1069
  function getCellValue(
@@ -1199,7 +1219,11 @@ export default defineComponent({
1199
1219
  resetVirtualScroll,
1200
1220
  scrollTo,
1201
1221
  setExpanded,
1202
- sort
1222
+ sort,
1223
+ firstPage,
1224
+ prevPage,
1225
+ nextPage,
1226
+ lastPage
1203
1227
  })
1204
1228
 
1205
1229
  return {
@@ -1247,7 +1271,8 @@ export default defineComponent({
1247
1271
  displayPagination,
1248
1272
  onTrClick,
1249
1273
  onTrDblClick,
1250
- onTrContextMenu
1274
+ onTrContextMenu,
1275
+ hasPaginationSlot
1251
1276
  }
1252
1277
  }
1253
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
  }
@@ -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 { DlTable, DlOptionGroup, DlSwitch, DlInput } from '../components'
124
- import { defineComponent } from 'vue-demi'
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 {