2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-12 13:02:20 +00:00
|
|
|
<div :class="cx('root')" v-bind="ptmi('root')">
|
2023-06-01 12:02:56 +00:00
|
|
|
<div v-if="$slots.header" :class="cx('header')" v-bind="ptm('header')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<slot name="header"></slot>
|
|
|
|
</div>
|
|
|
|
<DVPaginator
|
|
|
|
v-if="paginatorTop"
|
|
|
|
:rows="d_rows"
|
|
|
|
:first="d_first"
|
|
|
|
:totalRecords="getTotalRecords"
|
|
|
|
:pageLinkSize="pageLinkSize"
|
|
|
|
:template="paginatorTemplate"
|
|
|
|
:rowsPerPageOptions="rowsPerPageOptions"
|
|
|
|
:currentPageReportTemplate="currentPageReportTemplate"
|
2024-04-25 21:39:48 +00:00
|
|
|
:class="cx('paginator', { position: 'top' })"
|
2022-09-14 11:26:01 +00:00
|
|
|
:alwaysShow="alwaysShowPaginator"
|
|
|
|
@page="onPage($event)"
|
2023-06-01 12:02:56 +00:00
|
|
|
:unstyled="unstyled"
|
2023-05-09 22:39:10 +00:00
|
|
|
:pt="ptm('paginator')"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
|
|
|
<template v-if="$slots.paginatorstart" #start>
|
|
|
|
<slot name="paginatorstart"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatorend" #end>
|
|
|
|
<slot name="paginatorend"></slot>
|
|
|
|
</template>
|
|
|
|
</DVPaginator>
|
2023-06-01 12:02:56 +00:00
|
|
|
<div :class="cx('content')" v-bind="ptm('content')">
|
2023-11-15 09:51:35 +00:00
|
|
|
<template v-if="!empty">
|
|
|
|
<slot v-if="$slots.list && layout === 'list'" name="list" :items="items"></slot>
|
|
|
|
<slot v-if="$slots.grid && layout === 'grid'" name="grid" :items="items"></slot>
|
|
|
|
</template>
|
|
|
|
<div v-else :class="cx('emptyMessage')" v-bind="ptm('emptyMessage')">
|
|
|
|
<slot name="empty" :layout="layout">
|
|
|
|
{{ emptyMessageText }}
|
|
|
|
</slot>
|
2022-09-14 11:26:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<DVPaginator
|
|
|
|
v-if="paginatorBottom"
|
|
|
|
:rows="d_rows"
|
|
|
|
:first="d_first"
|
|
|
|
:totalRecords="getTotalRecords"
|
|
|
|
:pageLinkSize="pageLinkSize"
|
|
|
|
:template="paginatorTemplate"
|
|
|
|
:rowsPerPageOptions="rowsPerPageOptions"
|
|
|
|
:currentPageReportTemplate="currentPageReportTemplate"
|
2024-04-25 21:39:48 +00:00
|
|
|
:class="cx('paginator', { position: 'bottom' })"
|
2022-09-14 11:26:01 +00:00
|
|
|
:alwaysShow="alwaysShowPaginator"
|
|
|
|
@page="onPage($event)"
|
2023-06-01 12:02:56 +00:00
|
|
|
:unstyled="unstyled"
|
2023-07-13 12:22:16 +00:00
|
|
|
:pt="ptm('paginator')"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
|
|
|
<template v-if="$slots.paginatorstart" #start>
|
|
|
|
<slot name="paginatorstart"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatorend" #end>
|
|
|
|
<slot name="paginatorend"></slot>
|
|
|
|
</template>
|
|
|
|
</DVPaginator>
|
2023-06-01 12:02:56 +00:00
|
|
|
<div v-if="$slots.footer" :class="cx('footer')" v-bind="ptm('footer')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<slot name="footer"></slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
2023-05-09 22:39:10 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
<script>
|
|
|
|
import Paginator from 'primevue/paginator';
|
2023-05-09 22:39:10 +00:00
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-06-06 13:04:43 +00:00
|
|
|
import BaseDataView from './BaseDataView.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DataView',
|
2023-06-01 12:02:56 +00:00
|
|
|
extends: BaseDataView,
|
2024-02-12 13:02:20 +00:00
|
|
|
inheritAttrs: false,
|
2022-09-06 12:03:37 +00:00
|
|
|
emits: ['update:first', 'update:rows', 'page'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
d_first: this.first,
|
|
|
|
d_rows: this.rows
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
first(newValue) {
|
|
|
|
this.d_first = newValue;
|
|
|
|
},
|
|
|
|
rows(newValue) {
|
|
|
|
this.d_rows = newValue;
|
|
|
|
},
|
|
|
|
sortField() {
|
|
|
|
this.resetPage();
|
|
|
|
},
|
|
|
|
sortOrder() {
|
|
|
|
this.resetPage();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getKey(item, index) {
|
|
|
|
return this.dataKey ? ObjectUtils.resolveFieldData(item, this.dataKey) : index;
|
|
|
|
},
|
|
|
|
onPage(event) {
|
|
|
|
this.d_first = event.first;
|
|
|
|
this.d_rows = event.rows;
|
|
|
|
|
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
this.$emit('update:rows', this.d_rows);
|
|
|
|
this.$emit('page', event);
|
|
|
|
},
|
|
|
|
sort() {
|
|
|
|
if (this.value) {
|
|
|
|
const value = [...this.value];
|
2023-10-06 02:00:36 +00:00
|
|
|
const comparer = ObjectUtils.localeComparator();
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
value.sort((data1, data2) => {
|
|
|
|
let value1 = ObjectUtils.resolveFieldData(data1, this.sortField);
|
|
|
|
let value2 = ObjectUtils.resolveFieldData(data2, this.sortField);
|
|
|
|
|
2023-10-06 22:59:00 +00:00
|
|
|
return ObjectUtils.sort(value1, value2, this.sortOrder, comparer);
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return value;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resetPage() {
|
|
|
|
this.d_first = 0;
|
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
getTotalRecords() {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.totalRecords) return this.totalRecords;
|
|
|
|
else return this.value ? this.value.length : 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
empty() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return !this.value || this.value.length === 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-11-15 09:51:35 +00:00
|
|
|
emptyMessageText() {
|
|
|
|
return this.$primevue.config?.locale?.emptyMessage || '';
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
paginatorTop() {
|
|
|
|
return this.paginator && (this.paginatorPosition !== 'bottom' || this.paginatorPosition === 'both');
|
|
|
|
},
|
|
|
|
paginatorBottom() {
|
|
|
|
return this.paginator && (this.paginatorPosition !== 'top' || this.paginatorPosition === 'both');
|
|
|
|
},
|
|
|
|
items() {
|
|
|
|
if (this.value && this.value.length) {
|
|
|
|
let data = this.value;
|
|
|
|
|
|
|
|
if (data && data.length && this.sortField) {
|
|
|
|
data = this.sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.paginator) {
|
|
|
|
const first = this.lazy ? 0 : this.d_first;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return data.slice(first, first + this.d_rows);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return data;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
DVPaginator: Paginator
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|