2019-06-27 21:17:21 +00:00
|
|
|
<template>
|
2020-09-27 18:29:11 +00:00
|
|
|
<div :class="containerClass" data-scrollselectors=".p-datatable-scrollable-body, .p-datatable-unfrozen-view .p-datatable-scrollable-body">
|
2019-06-27 21:17:21 +00:00
|
|
|
<slot></slot>
|
2020-07-18 11:11:41 +00:00
|
|
|
<div class="p-datatable-loading-overlay p-component-overlay" v-if="loading">
|
|
|
|
<i :class="loadingIconClass"></i>
|
2019-07-02 14:29:30 +00:00
|
|
|
</div>
|
2020-09-17 12:19:11 +00:00
|
|
|
<div class="p-datatable-header" v-if="$slots.header">
|
2019-11-18 07:42:32 +00:00
|
|
|
<slot name="header"></slot>
|
|
|
|
</div>
|
|
|
|
<DTPaginator v-if="paginatorTop" :rows="d_rows" :first="d_first" :totalRecords="totalRecordsLength" :pageLinkSize="pageLinkSize" :template="paginatorTemplate" :rowsPerPageOptions="rowsPerPageOptions"
|
|
|
|
:currentPageReportTemplate="currentPageReportTemplate" class="p-paginator-top" @page="onPage($event)" :alwaysShow="alwaysShowPaginator">
|
2020-09-17 12:19:11 +00:00
|
|
|
<template #left v-if="$slots.paginatorLeft">
|
2019-11-18 07:42:32 +00:00
|
|
|
<slot name="paginatorLeft"></slot>
|
|
|
|
</template>
|
2020-09-17 12:19:11 +00:00
|
|
|
<template #right v-if="$slots.paginatorRight">
|
2019-11-18 07:42:32 +00:00
|
|
|
<slot name="paginatorRight"></slot>
|
|
|
|
</template>
|
|
|
|
</DTPaginator>
|
2019-11-18 13:56:33 +00:00
|
|
|
<div class="p-datatable-wrapper" v-if="!scrollable">
|
2019-12-26 11:24:53 +00:00
|
|
|
<table ref="table" role="grid">
|
2019-11-18 07:42:32 +00:00
|
|
|
<DTTableHeader :columnGroup="headerColumnGroup" :columns="columns" :rowGroupMode="rowGroupMode"
|
|
|
|
:groupRowsBy="groupRowsBy" :resizableColumns="resizableColumns" :allRowsSelected="allRowsSelected" :empty="empty"
|
2021-02-06 22:42:14 +00:00
|
|
|
:sortMode="sortMode" :sortField="d_sortField" :sortOrder="d_sortOrder" :multiSortMeta="d_multiSortMeta" :filters="d_filters" :filterDisplay="filterDisplay"
|
|
|
|
@column-click="onColumnHeaderClick($event)" @column-mousedown="onColumnHeaderMouseDown($event)" @filter-change="onFilterChange" @filter-apply="onFilterApply"
|
2019-11-18 07:42:32 +00:00
|
|
|
@column-dragstart="onColumnHeaderDragStart($event)" @column-dragover="onColumnHeaderDragOver($event)" @column-dragleave="onColumnHeaderDragLeave($event)" @column-drop="onColumnHeaderDrop($event)"
|
|
|
|
@column-resizestart="onColumnResizeStart($event)" @checkbox-change="toggleRowsWithCheckbox($event)" />
|
2020-04-07 12:29:31 +00:00
|
|
|
<DTTableBody :value="dataToRender" :columns="columns" :empty="empty" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
2019-11-18 12:00:43 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy"
|
2019-11-18 12:09:29 +00:00
|
|
|
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
2020-09-17 12:19:11 +00:00
|
|
|
:editingRows="editingRows" :editingRowKeys="d_editingRowKeys" :templates="$slots" :loading="loading"
|
2019-12-09 08:34:31 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
|
2019-11-18 11:52:17 +00:00
|
|
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
|
|
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
|
|
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
|
|
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)"/>
|
2019-11-18 08:00:39 +00:00
|
|
|
<DTTableFooter :columnGroup="footerColumnGroup" :columns="columns" />
|
2019-06-27 21:17:21 +00:00
|
|
|
</table>
|
2019-11-18 07:42:32 +00:00
|
|
|
</div>
|
2019-11-18 13:56:33 +00:00
|
|
|
<div class="p-datatable-scrollable-wrapper" v-else>
|
2020-07-10 13:23:36 +00:00
|
|
|
<DTScrollableView v-if="hasFrozenColumns" :scrollHeight="scrollHeight" :columns="frozenColumns" :frozenWidth="frozenWidth" :frozen="true"
|
2020-09-23 19:12:48 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :headerColumnGroup="frozenHeaderColumnGroup" :footerColumnGroup="frozenFooterColumnGroup">
|
|
|
|
<template #header="slotProps">
|
|
|
|
<DTTableHeader :columnGroup="slotProps.columnGroup" :columns="slotProps.columns" :rowGroupMode="rowGroupMode"
|
2019-11-18 13:56:33 +00:00
|
|
|
:groupRowsBy="groupRowsBy" :resizableColumns="resizableColumns" :allRowsSelected="allRowsSelected" :empty="empty"
|
|
|
|
:sortMode="sortMode" :sortField="d_sortField" :sortOrder="d_sortOrder" :multiSortMeta="d_multiSortMeta"
|
|
|
|
@column-click="onColumnHeaderClick($event)" @column-mousedown="onColumnHeaderMouseDown($event)"
|
|
|
|
@column-dragstart="onColumnHeaderDragStart($event)" @column-dragover="onColumnHeaderDragOver($event)" @column-dragleave="onColumnHeaderDragLeave($event)" @column-drop="onColumnHeaderDrop($event)"
|
|
|
|
@column-resizestart="onColumnResizeStart($event)" @checkbox-change="toggleRowsWithCheckbox($event)" />
|
|
|
|
</template>
|
2020-09-23 19:12:48 +00:00
|
|
|
<template #body="slotProps">
|
|
|
|
<DTTableBody :value="dataToRender" :columns="slotProps.columns" :empty="empty" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
2019-11-18 13:56:33 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy"
|
|
|
|
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
2020-09-17 12:19:11 +00:00
|
|
|
:editingRows="editingRows" :editingRowKeys="d_editingRowKeys" :templates="$slots" :loading="loading"
|
2019-12-09 08:34:31 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
|
2019-11-18 13:56:33 +00:00
|
|
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
|
|
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
|
|
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
|
|
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)"/>
|
|
|
|
</template>
|
2020-09-23 19:12:48 +00:00
|
|
|
<template #frozenbody="slotProps">
|
|
|
|
<DTTableBody v-if="frozenValue" :value="frozenValue" :columns="slotProps.columns" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
2019-11-18 14:52:30 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy"
|
|
|
|
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
2020-09-17 12:19:11 +00:00
|
|
|
:editingRows="editingRows" :editingRowKeys="d_editingRowKeys" :templates="$slots" :loading="loading"
|
2019-12-09 08:34:31 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
|
2019-11-18 14:52:30 +00:00
|
|
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
|
|
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
|
|
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
|
|
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)"/>
|
|
|
|
</template>
|
2020-09-23 19:12:48 +00:00
|
|
|
<template #footer="slotProps">
|
|
|
|
<DTTableFooter :columnGroup="slotProps.columnGroup" :columns="slotProps.columns" />
|
2019-11-19 07:51:23 +00:00
|
|
|
</template>
|
|
|
|
</DTScrollableView>
|
2019-11-19 11:54:24 +00:00
|
|
|
<DTScrollableView :scrollHeight="scrollHeight" :columns="scrollableColumns" :frozenWidth="frozenWidth" :rows="rows"
|
2020-07-10 13:23:36 +00:00
|
|
|
:virtualScroll="virtualScroll" :virtualRowHeight="virtualRowHeight" :totalRecords="totalRecordsLength" @virtual-scroll="onVirtualScroll"
|
2020-09-23 19:12:48 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :headerColumnGroup="headerColumnGroup" :footerColumnGroup="footerColumnGroup">
|
|
|
|
<template #header="slotProps">
|
|
|
|
<DTTableHeader :columnGroup="slotProps.columnGroup" :columns="slotProps.columns" :rowGroupMode="rowGroupMode"
|
2019-11-19 07:51:23 +00:00
|
|
|
:groupRowsBy="groupRowsBy" :resizableColumns="resizableColumns" :allRowsSelected="allRowsSelected" :empty="empty"
|
|
|
|
:sortMode="sortMode" :sortField="d_sortField" :sortOrder="d_sortOrder" :multiSortMeta="d_multiSortMeta"
|
|
|
|
@column-click="onColumnHeaderClick($event)" @column-mousedown="onColumnHeaderMouseDown($event)"
|
|
|
|
@column-dragstart="onColumnHeaderDragStart($event)" @column-dragover="onColumnHeaderDragOver($event)" @column-dragleave="onColumnHeaderDragLeave($event)" @column-drop="onColumnHeaderDrop($event)"
|
|
|
|
@column-resizestart="onColumnResizeStart($event)" @checkbox-change="toggleRowsWithCheckbox($event)" />
|
|
|
|
</template>
|
2020-09-23 19:12:48 +00:00
|
|
|
<template #body="slotProps">
|
|
|
|
<DTTableBody :value="dataToRender" :columns="slotProps.columns" :empty="empty" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
2019-11-19 07:51:23 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy"
|
|
|
|
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
2020-09-17 12:19:11 +00:00
|
|
|
:editingRows="editingRows" :editingRowKeys="d_editingRowKeys" :templates="$slots" :loading="loading"
|
2019-12-09 08:34:31 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
|
2019-11-19 07:51:23 +00:00
|
|
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
|
|
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
|
|
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
|
|
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)"/>
|
|
|
|
</template>
|
2020-09-23 19:12:48 +00:00
|
|
|
<template #frozenbody="slotProps">
|
|
|
|
<DTTableBody v-if="frozenValue" :value="frozenValue" :columns="slotProps.columns" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
2019-11-19 07:51:23 +00:00
|
|
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy"
|
|
|
|
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
2020-09-17 12:19:11 +00:00
|
|
|
:editingRows="editingRows" :editingRowKeys="d_editingRowKeys" :templates="$slots" :loading="loading"
|
2019-12-09 08:34:31 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup" @row-click="onRowClick($event)" @row-rightclick="onRowRightClick($event)" @row-touchend="onRowTouchEnd" @row-keydown="onRowKeyDown"
|
2019-11-19 07:51:23 +00:00
|
|
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
|
|
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
|
|
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
|
|
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)"/>
|
|
|
|
</template>
|
2020-09-23 19:12:48 +00:00
|
|
|
<template #footer="slotProps">
|
|
|
|
<DTTableFooter :columnGroup="slotProps.columnGroup" :columns="slotProps.columns" />
|
2019-11-18 13:56:33 +00:00
|
|
|
</template>
|
|
|
|
</DTScrollableView>
|
|
|
|
</div>
|
2019-11-18 07:42:32 +00:00
|
|
|
<DTPaginator v-if="paginatorBottom" :rows="d_rows" :first="d_first" :totalRecords="totalRecordsLength" :pageLinkSize="pageLinkSize" :template="paginatorTemplate" :rowsPerPageOptions="rowsPerPageOptions"
|
|
|
|
:currentPageReportTemplate="currentPageReportTemplate" class="p-paginator-bottom" @page="onPage($event)" :alwaysShow="alwaysShowPaginator">
|
2020-09-17 12:19:11 +00:00
|
|
|
<template #left v-if="$slots.paginatorLeft">
|
2019-11-18 07:42:32 +00:00
|
|
|
<slot name="paginatorLeft"></slot>
|
|
|
|
</template>
|
2020-09-17 12:19:11 +00:00
|
|
|
<template #right v-if="$slots.paginatorRight">
|
2019-11-18 07:42:32 +00:00
|
|
|
<slot name="paginatorRight"></slot>
|
|
|
|
</template>
|
|
|
|
</DTPaginator>
|
2020-09-17 12:19:11 +00:00
|
|
|
<div class="p-datatable-footer" v-if="$slots.footer">
|
2019-11-18 07:42:32 +00:00
|
|
|
<slot name="footer"></slot>
|
2019-06-27 21:17:21 +00:00
|
|
|
</div>
|
2020-07-18 08:02:10 +00:00
|
|
|
<div ref="resizeHelper" class="p-column-resizer-helper" style="display: none"></div>
|
2019-10-17 11:50:20 +00:00
|
|
|
<span ref="reorderIndicatorUp" class="pi pi-arrow-down p-datatable-reorder-indicator-up" style="position: absolute; display: none" v-if="reorderableColumns" />
|
|
|
|
<span ref="reorderIndicatorDown" class="pi pi-arrow-up p-datatable-reorder-indicator-down" style="position: absolute; display: none" v-if="reorderableColumns" />
|
2019-06-27 21:17:21 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-02-06 09:26:12 +00:00
|
|
|
import {ObjectUtils,FilterUtils,DomHandler} from 'primevue/utils';
|
|
|
|
import {FilterMatchMode,FilterOperator} from 'primevue/api';
|
2021-01-18 11:20:34 +00:00
|
|
|
import Paginator from 'primevue/paginator';
|
2019-11-18 13:56:33 +00:00
|
|
|
import ScrollableView from './ScrollableView.vue';
|
2019-11-18 07:42:32 +00:00
|
|
|
import TableHeader from './TableHeader.vue';
|
2019-11-18 11:52:17 +00:00
|
|
|
import TableBody from './TableBody.vue';
|
2019-11-18 08:00:39 +00:00
|
|
|
import TableFooter from './TableFooter.vue';
|
2019-06-28 14:40:32 +00:00
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
export default {
|
2020-10-21 18:03:17 +00:00
|
|
|
emits: ['update:first', 'update:rows', 'page', 'update:sortField', 'update:sortOrder', 'update:multiSortMeta', 'sort', 'filter', 'row-click',
|
|
|
|
'update:selection', 'row-select', 'row-unselect', 'update:contextMenuSelection', 'row-contextmenu', 'row-unselect-all', 'row-select-all',
|
|
|
|
'column-resize-end', 'column-reorder', 'row-reorder', 'update:expandedRows', 'row-collapse', 'row-expand',
|
2021-01-20 09:37:50 +00:00
|
|
|
'update:expandedRowGroups', 'rowgroup-collapse', 'rowgroup-expand', 'update:filters', 'virtual-scroll', 'state-restore', 'state-save',
|
2020-10-21 18:03:17 +00:00
|
|
|
'cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel', 'update:editingRows', 'row-edit-init', 'row-edit-save', 'row-edit-cancel'],
|
2019-06-27 21:17:21 +00:00
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
dataKey: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2019-06-29 11:29:19 +00:00
|
|
|
},
|
|
|
|
rows: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
first: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
totalRecords: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
paginator: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
paginatorPosition: {
|
|
|
|
type: String,
|
|
|
|
default: 'bottom'
|
|
|
|
},
|
|
|
|
alwaysShowPaginator: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
paginatorTemplate: {
|
|
|
|
type: String,
|
|
|
|
default: 'FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown'
|
|
|
|
},
|
|
|
|
pageLinkSize: {
|
|
|
|
type: Number,
|
|
|
|
default: 5
|
|
|
|
},
|
|
|
|
rowsPerPageOptions: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
currentPageReportTemplate: {
|
|
|
|
type: String,
|
|
|
|
default: '({currentPage} of {totalPages})'
|
|
|
|
},
|
|
|
|
lazy: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2019-06-29 11:34:29 +00:00
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
loadingIcon: {
|
|
|
|
type: String,
|
|
|
|
default: 'pi pi-spinner'
|
2019-07-01 13:50:55 +00:00
|
|
|
},
|
|
|
|
sortField: {
|
2020-11-25 11:45:42 +00:00
|
|
|
type: [String, Function],
|
2019-07-01 13:50:55 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
sortOrder: {
|
|
|
|
type: Number,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
defaultSortOrder: {
|
|
|
|
type: Number,
|
|
|
|
default: 1
|
2019-07-02 10:15:50 +00:00
|
|
|
},
|
|
|
|
multiSortMeta: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
sortMode: {
|
|
|
|
type: String,
|
|
|
|
default: 'single'
|
2019-07-02 12:57:03 +00:00
|
|
|
},
|
2020-04-18 14:41:50 +00:00
|
|
|
removableSort: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2019-07-02 12:57:03 +00:00
|
|
|
filters: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
2019-07-03 10:07:57 +00:00
|
|
|
},
|
2021-02-06 09:26:12 +00:00
|
|
|
filterDisplay: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
globalFilterFields: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
2020-04-19 09:09:27 +00:00
|
|
|
filterLocale: {
|
|
|
|
type: String,
|
2020-04-19 09:52:57 +00:00
|
|
|
default: undefined
|
2020-04-19 09:09:27 +00:00
|
|
|
},
|
2019-07-03 10:07:57 +00:00
|
|
|
selection: {
|
|
|
|
type: [Array,Object],
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
selectionMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
compareSelectionBy: {
|
|
|
|
type: String,
|
|
|
|
default: 'deepEquals'
|
|
|
|
},
|
|
|
|
metaKeySelection: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
2020-04-07 12:29:31 +00:00
|
|
|
contextMenu: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2019-12-09 08:34:31 +00:00
|
|
|
contextMenuSelection: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
2019-07-03 10:07:57 +00:00
|
|
|
rowHover: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2019-07-09 13:21:42 +00:00
|
|
|
},
|
|
|
|
csvSeparator: {
|
|
|
|
type: String,
|
|
|
|
default: ','
|
|
|
|
},
|
|
|
|
exportFilename: {
|
|
|
|
type: String,
|
|
|
|
default: 'download'
|
2019-07-10 14:20:12 +00:00
|
|
|
},
|
|
|
|
autoLayout: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2019-08-07 13:50:07 +00:00
|
|
|
},
|
|
|
|
resizableColumns: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
columnResizeMode: {
|
|
|
|
type: String,
|
|
|
|
default: 'fit'
|
2019-10-17 11:50:20 +00:00
|
|
|
},
|
|
|
|
reorderableColumns: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2019-10-21 06:21:15 +00:00
|
|
|
},
|
|
|
|
expandedRows: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedRowIcon: {
|
|
|
|
type: String,
|
|
|
|
default: 'pi-chevron-down'
|
|
|
|
},
|
|
|
|
collapsedRowIcon: {
|
|
|
|
type: String,
|
|
|
|
default: 'pi-chevron-right'
|
2019-10-21 08:50:13 +00:00
|
|
|
},
|
|
|
|
rowGroupMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
groupRowsBy: {
|
|
|
|
type: [Array,String],
|
|
|
|
default: null
|
2019-10-21 14:20:06 +00:00
|
|
|
},
|
|
|
|
expandableRowGroups: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
expandedRowGroups: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
2019-10-22 07:36:04 +00:00
|
|
|
},
|
|
|
|
stateStorage: {
|
|
|
|
type: String,
|
|
|
|
default: 'session'
|
|
|
|
},
|
|
|
|
stateKey: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2019-10-30 10:32:46 +00:00
|
|
|
},
|
|
|
|
editMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2019-10-30 11:58:57 +00:00
|
|
|
},
|
|
|
|
editingRows: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
2019-11-01 10:45:49 +00:00
|
|
|
},
|
|
|
|
rowClass: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2019-11-18 13:56:33 +00:00
|
|
|
},
|
|
|
|
scrollable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
scrollHeight: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2019-11-18 14:52:30 +00:00
|
|
|
},
|
|
|
|
frozenValue: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
2019-11-19 07:51:23 +00:00
|
|
|
frozenWidth: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2019-11-19 11:54:24 +00:00
|
|
|
},
|
|
|
|
virtualScroll: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
virtualRowHeight: {
|
|
|
|
type: Number,
|
2019-11-19 14:02:36 +00:00
|
|
|
default: 28
|
2019-11-19 11:54:24 +00:00
|
|
|
},
|
|
|
|
virtualScrollDelay: {
|
|
|
|
type: Number,
|
2019-11-19 14:02:36 +00:00
|
|
|
default: 150
|
2019-11-19 07:51:23 +00:00
|
|
|
}
|
2019-06-27 21:17:21 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2019-06-29 11:29:19 +00:00
|
|
|
d_first: this.first,
|
2019-07-01 13:50:55 +00:00
|
|
|
d_rows: this.rows,
|
|
|
|
d_sortField: this.sortField,
|
2019-07-02 10:15:50 +00:00
|
|
|
d_sortOrder: this.sortOrder,
|
2019-07-03 10:07:57 +00:00
|
|
|
d_multiSortMeta: this.multiSortMeta ? [...this.multiSortMeta] : [],
|
2019-10-17 11:50:20 +00:00
|
|
|
d_selectionKeys: null,
|
2019-10-21 06:21:15 +00:00
|
|
|
d_expandedRowKeys: null,
|
2019-10-30 11:58:57 +00:00
|
|
|
d_columnOrder: null,
|
2021-02-06 22:42:14 +00:00
|
|
|
d_editingRowKeys: null,
|
|
|
|
d_filters: this.cloneFilters(this.filters)
|
2019-06-27 21:17:21 +00:00
|
|
|
};
|
|
|
|
},
|
2019-07-03 10:07:57 +00:00
|
|
|
rowTouched: false,
|
|
|
|
anchorRowIndex: null,
|
|
|
|
rangeRowIndex: null,
|
2019-08-07 13:50:07 +00:00
|
|
|
documentColumnResizeListener: null,
|
|
|
|
documentColumnResizeEndListener: null,
|
|
|
|
lastResizeHelperX: null,
|
|
|
|
resizeColumnElement: null,
|
2019-10-17 11:50:20 +00:00
|
|
|
columnResizing: false,
|
|
|
|
colReorderIconWidth: null,
|
|
|
|
colReorderIconHeight: null,
|
|
|
|
draggedColumn: null,
|
2019-10-17 13:56:54 +00:00
|
|
|
draggedRowIndex: null,
|
|
|
|
droppedRowIndex: null,
|
|
|
|
rowDragging: null,
|
2019-10-22 07:36:04 +00:00
|
|
|
columnWidthsState: null,
|
|
|
|
tableWidthState: null,
|
|
|
|
columnWidthsRestored: false,
|
2019-11-19 11:54:24 +00:00
|
|
|
virtualScrollTimer: null,
|
2019-06-29 11:29:19 +00:00
|
|
|
watch: {
|
|
|
|
first(newValue) {
|
|
|
|
this.d_first = newValue;
|
|
|
|
},
|
|
|
|
rows(newValue) {
|
|
|
|
this.d_rows = newValue;
|
2019-07-01 13:50:55 +00:00
|
|
|
},
|
|
|
|
sortField(newValue) {
|
|
|
|
this.d_sortField = newValue;
|
|
|
|
},
|
|
|
|
sortOrder(newValue) {
|
|
|
|
this.d_sortOrder = newValue;
|
2019-07-02 10:15:50 +00:00
|
|
|
},
|
|
|
|
multiSortMeta(newValue) {
|
|
|
|
this.d_multiSortMeta = newValue;
|
2019-07-03 10:07:57 +00:00
|
|
|
},
|
|
|
|
selection(newValue) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
this.updateSelectionKeys(newValue);
|
|
|
|
}
|
2019-10-21 06:21:15 +00:00
|
|
|
},
|
|
|
|
expandedRows(newValue) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
this.updateExpandedRowKeys(newValue);
|
|
|
|
}
|
2019-10-30 11:58:57 +00:00
|
|
|
},
|
|
|
|
editingRows(newValue) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
this.updateEditingRowKeys(newValue);
|
|
|
|
}
|
2021-02-06 22:42:14 +00:00
|
|
|
},
|
|
|
|
filters(newValue) {
|
|
|
|
this.d_filters = this.cloneFilters(newValue);
|
2019-06-29 11:29:19 +00:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 07:36:04 +00:00
|
|
|
beforeMount() {
|
|
|
|
if (this.isStateful()) {
|
|
|
|
this.restoreState();
|
|
|
|
}
|
|
|
|
},
|
2019-06-27 21:17:21 +00:00
|
|
|
mounted() {
|
2019-10-17 11:50:20 +00:00
|
|
|
if (this.reorderableColumns) {
|
|
|
|
let columnOrder = [];
|
2021-02-02 13:21:10 +00:00
|
|
|
this.columns.forEach(col => columnOrder.push(this.columnProp(col, 'columnKey')||this.columnProp(col, 'field')));
|
2019-10-22 07:36:04 +00:00
|
|
|
this.d_columnOrder = columnOrder;
|
2019-10-17 11:50:20 +00:00
|
|
|
}
|
2019-06-27 21:17:21 +00:00
|
|
|
},
|
2020-09-17 12:19:11 +00:00
|
|
|
beforeUnmount() {
|
2019-08-07 13:50:07 +00:00
|
|
|
this.unbindColumnResizeEvents();
|
|
|
|
},
|
2019-10-22 07:36:04 +00:00
|
|
|
updated() {
|
|
|
|
if (this.isStateful()) {
|
|
|
|
this.saveState();
|
|
|
|
|
|
|
|
if (this.resizableColumns && !this.columnWidthsRestored) {
|
|
|
|
this.restoreColumnWidths();
|
|
|
|
this.columnWidthsRestored = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-06-27 21:17:21 +00:00
|
|
|
methods: {
|
2021-02-02 13:21:10 +00:00
|
|
|
columnProp(col, prop) {
|
2021-02-02 13:50:37 +00:00
|
|
|
return col.props ? ((col.type.props[prop].type === Boolean && col.props[prop] === '') ? true : col.props[prop]) : null;
|
2021-02-02 13:21:10 +00:00
|
|
|
},
|
2019-06-29 11:29:19 +00:00
|
|
|
onPage(event) {
|
|
|
|
this.d_first = event.first;
|
|
|
|
this.d_rows = event.rows;
|
|
|
|
|
2020-01-30 09:06:16 +00:00
|
|
|
let pageEvent = this.createLazyLoadEvent(event);
|
|
|
|
pageEvent.pageCount = event.pageCount;
|
|
|
|
pageEvent.page = event.page;
|
|
|
|
|
2019-06-29 11:29:19 +00:00
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
this.$emit('update:rows', this.d_rows);
|
2020-01-30 09:06:16 +00:00
|
|
|
this.$emit('page', pageEvent);
|
2019-07-01 13:50:55 +00:00
|
|
|
},
|
2019-11-18 07:42:32 +00:00
|
|
|
onColumnHeaderClick(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const column = e.column;
|
|
|
|
|
2021-02-02 13:21:10 +00:00
|
|
|
if (this.columnProp(column, 'sortable')) {
|
2019-07-02 10:15:50 +00:00
|
|
|
const targetNode = event.target;
|
2021-02-02 13:21:10 +00:00
|
|
|
const columnField = this.columnProp(column, 'sortField') || this.columnProp(column, 'field');
|
2019-07-01 13:50:55 +00:00
|
|
|
|
2019-10-01 13:00:26 +00:00
|
|
|
if (DomHandler.hasClass(targetNode, 'p-sortable-column') || DomHandler.hasClass(targetNode, 'p-column-title')
|
2019-07-02 10:15:50 +00:00
|
|
|
|| DomHandler.hasClass(targetNode, 'p-sortable-column-icon') || DomHandler.hasClass(targetNode.parentElement, 'p-sortable-column-icon')) {
|
|
|
|
DomHandler.clearSelection();
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2020-04-18 14:41:50 +00:00
|
|
|
if (this.sortMode === 'single') {
|
|
|
|
if (this.d_sortField === columnField) {
|
|
|
|
if (this.removableSort && (this.d_sortOrder * -1 === this.defaultSortOrder)) {
|
|
|
|
this.d_sortOrder = null;
|
|
|
|
this.d_sortField = null;
|
|
|
|
}
|
|
|
|
else {
|
2020-04-18 18:16:35 +00:00
|
|
|
this.d_sortOrder = this.d_sortOrder * -1;
|
2020-04-18 14:41:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.d_sortOrder = this.defaultSortOrder;
|
|
|
|
this.d_sortField = columnField;
|
|
|
|
}
|
2019-07-02 10:15:50 +00:00
|
|
|
|
2020-04-18 14:41:50 +00:00
|
|
|
this.$emit('update:sortField', this.d_sortField);
|
|
|
|
this.$emit('update:sortOrder', this.d_sortOrder);
|
2020-04-18 16:16:29 +00:00
|
|
|
this.resetPage();
|
2020-04-18 14:41:50 +00:00
|
|
|
}
|
|
|
|
else if (this.sortMode === 'multiple') {
|
2019-07-02 10:15:50 +00:00
|
|
|
let metaKey = event.metaKey || event.ctrlKey;
|
|
|
|
if (!metaKey) {
|
2020-04-18 14:41:50 +00:00
|
|
|
this.d_multiSortMeta = this.d_multiSortMeta.filter(meta => meta.field === columnField);
|
2019-07-02 10:15:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 14:41:50 +00:00
|
|
|
this.addMultiSortField(columnField);
|
|
|
|
this.$emit('update:multiSortMeta', this.d_multiSortMeta);
|
2019-10-01 13:00:26 +00:00
|
|
|
}
|
2019-07-02 10:15:50 +00:00
|
|
|
|
2020-01-30 09:06:16 +00:00
|
|
|
this.$emit('sort', this.createLazyLoadEvent(event));
|
2019-07-01 13:50:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-07-02 10:15:50 +00:00
|
|
|
sortSingle(value) {
|
2019-07-02 10:46:06 +00:00
|
|
|
let data = [...value];
|
2019-07-02 10:15:50 +00:00
|
|
|
|
|
|
|
data.sort((data1, data2) => {
|
|
|
|
let value1 = ObjectUtils.resolveFieldData(data1, this.d_sortField);
|
|
|
|
let value2 = ObjectUtils.resolveFieldData(data2, this.d_sortField);
|
2020-03-03 15:45:11 +00:00
|
|
|
|
2019-07-02 10:15:50 +00:00
|
|
|
let result = null;
|
|
|
|
|
|
|
|
if (value1 == null && value2 != null)
|
|
|
|
result = -1;
|
|
|
|
else if (value1 != null && value2 == null)
|
|
|
|
result = 1;
|
|
|
|
else if (value1 == null && value2 == null)
|
|
|
|
result = 0;
|
|
|
|
else if (typeof value1 === 'string' && typeof value2 === 'string')
|
|
|
|
result = value1.localeCompare(value2, undefined, { numeric: true });
|
|
|
|
else
|
|
|
|
result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;
|
2019-07-01 13:50:55 +00:00
|
|
|
|
2019-07-02 10:15:50 +00:00
|
|
|
return (this.d_sortOrder * result);
|
|
|
|
});
|
2019-07-01 13:50:55 +00:00
|
|
|
|
2019-07-02 10:15:50 +00:00
|
|
|
return data;
|
|
|
|
},
|
|
|
|
sortMultiple(value) {
|
2019-07-02 10:46:06 +00:00
|
|
|
let data = [...value];
|
2019-07-02 10:15:50 +00:00
|
|
|
|
|
|
|
data.sort((data1, data2) => {
|
|
|
|
return this.multisortField(data1, data2, 0);
|
|
|
|
});
|
2019-07-01 13:50:55 +00:00
|
|
|
|
2019-10-01 13:00:26 +00:00
|
|
|
return data;
|
2019-07-02 10:15:50 +00:00
|
|
|
},
|
|
|
|
multisortField(data1, data2, index) {
|
|
|
|
const value1 = ObjectUtils.resolveFieldData(data1, this.d_multiSortMeta[index].field);
|
|
|
|
const value2 = ObjectUtils.resolveFieldData(data2, this.d_multiSortMeta[index].field);
|
|
|
|
let result = null;
|
2019-07-01 13:50:55 +00:00
|
|
|
|
2019-07-02 10:15:50 +00:00
|
|
|
if (typeof value1 === 'string' || value1 instanceof String) {
|
|
|
|
if (value1.localeCompare && (value1 !== value2)) {
|
|
|
|
return (this.d_multiSortMeta[index].order * value1.localeCompare(value2, undefined, { numeric: true }));
|
|
|
|
}
|
2019-07-01 13:50:55 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-07-02 10:15:50 +00:00
|
|
|
result = (value1 < value2) ? -1 : 1;
|
2019-07-01 13:50:55 +00:00
|
|
|
}
|
2019-07-02 10:15:50 +00:00
|
|
|
|
|
|
|
if (value1 === value2) {
|
|
|
|
return (this.d_multiSortMeta.length - 1) > (index) ? (this.multisortField(data1, data2, index + 1)) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (this.d_multiSortMeta[index].order * result);
|
|
|
|
},
|
2020-04-18 14:45:13 +00:00
|
|
|
addMultiSortField(field) {
|
2020-04-18 14:41:50 +00:00
|
|
|
let index = this.d_multiSortMeta.findIndex(meta => meta.field === field);
|
2020-04-18 14:45:13 +00:00
|
|
|
|
2020-04-18 14:41:50 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
if (this.removableSort && (this.d_multiSortMeta[index].order * -1 === this.defaultSortOrder))
|
|
|
|
this.d_multiSortMeta.splice(index, 1);
|
|
|
|
else
|
|
|
|
this.d_multiSortMeta[index] = {field: field, order: this.d_multiSortMeta[index].order * -1};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.d_multiSortMeta.push({field: field, order: this.defaultSortOrder});
|
2019-07-02 10:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.d_multiSortMeta = [...this.d_multiSortMeta];
|
2019-07-02 12:57:03 +00:00
|
|
|
},
|
|
|
|
filter(data) {
|
2021-02-02 15:16:51 +00:00
|
|
|
this.d_first = 0;
|
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
|
2021-02-06 09:26:12 +00:00
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let globalFilterFieldsArray;
|
|
|
|
if (this.filters['global']) {
|
|
|
|
globalFilterFieldsArray = this.globalFilterFields|| this.columns.map(col => this.columnProp(col, 'filterField') || this.columnProp(col, 'field'));
|
|
|
|
}
|
|
|
|
|
2019-07-02 12:57:03 +00:00
|
|
|
let filteredValue = [];
|
|
|
|
|
2021-02-06 09:26:12 +00:00
|
|
|
for (let i = 0; i < data.length; i++) {
|
2019-07-02 12:57:03 +00:00
|
|
|
let localMatch = true;
|
|
|
|
let globalMatch = false;
|
2021-02-06 09:26:12 +00:00
|
|
|
let localFiltered = false;
|
2019-07-02 12:57:03 +00:00
|
|
|
|
2021-02-06 09:26:12 +00:00
|
|
|
for (let prop in this.filters) {
|
|
|
|
if (Object.prototype.hasOwnProperty.call(this.filters, prop) && prop !== 'global') {
|
|
|
|
localFiltered = true;
|
|
|
|
let filterField = prop;
|
|
|
|
let filterMeta = this.filters[filterField];
|
|
|
|
|
2021-02-06 23:47:55 +00:00
|
|
|
if (filterMeta.operator) {
|
|
|
|
for (let filterConstraint of filterMeta.constraints) {
|
|
|
|
localMatch = this.executeLocalFilter(filterField, data[i], filterConstraint);
|
2019-07-02 12:57:03 +00:00
|
|
|
|
2021-02-06 23:47:55 +00:00
|
|
|
if ((filterMeta.operator === FilterOperator.OR && localMatch) || (filterMeta.operator === FilterOperator.AND && !localMatch)) {
|
2021-02-06 09:26:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
localMatch = this.executeLocalFilter(filterField, data[i], filterMeta);
|
|
|
|
}
|
|
|
|
|
2019-07-02 12:57:03 +00:00
|
|
|
if (!localMatch) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-02-06 09:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.filters['global'] && !globalMatch && globalFilterFieldsArray) {
|
|
|
|
for(let j = 0; j < globalFilterFieldsArray.length; j++) {
|
|
|
|
let globalFilterField = globalFilterFieldsArray[j];
|
|
|
|
globalMatch = FilterUtils[this.filters['global'].matchMode || FilterMatchMode.CONTAINS](ObjectUtils.resolveFieldData(data[i], globalFilterField), this.filters['global'].value, this.filterLocale);
|
2019-07-02 12:57:03 +00:00
|
|
|
|
2021-02-06 09:26:12 +00:00
|
|
|
if (globalMatch) {
|
|
|
|
break;
|
|
|
|
}
|
2019-07-02 12:57:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 09:26:12 +00:00
|
|
|
let matches;
|
|
|
|
if (this.filters['global']) {
|
|
|
|
matches = localFiltered ? (localFiltered && localMatch && globalMatch) : globalMatch;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
matches = localFiltered && localMatch;
|
2019-07-02 12:57:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 19:20:09 +00:00
|
|
|
if (matches) {
|
2021-02-06 09:26:12 +00:00
|
|
|
filteredValue.push(this.value[i]);
|
2019-07-02 12:57:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 09:26:12 +00:00
|
|
|
if (filteredValue.length === this.value.length) {
|
2019-07-02 12:57:03 +00:00
|
|
|
filteredValue = data;
|
|
|
|
}
|
|
|
|
|
2020-07-03 11:28:53 +00:00
|
|
|
let filterEvent = this.createLazyLoadEvent();
|
2020-02-07 07:23:19 +00:00
|
|
|
filterEvent.filteredValue = filteredValue;
|
2020-01-30 09:06:16 +00:00
|
|
|
this.$emit('filter', filterEvent);
|
2019-07-10 17:59:21 +00:00
|
|
|
|
2019-07-02 12:57:03 +00:00
|
|
|
return filteredValue;
|
2019-07-03 10:07:57 +00:00
|
|
|
},
|
2021-02-06 09:26:12 +00:00
|
|
|
executeLocalFilter(field, rowData, filterMeta) {
|
|
|
|
let filterValue = filterMeta.value;
|
|
|
|
let filterMatchMode = filterMeta.matchMode || FilterMatchMode.STARTS_WITH;
|
|
|
|
let dataFieldValue = ObjectUtils.resolveFieldData(rowData, field);
|
|
|
|
let filterConstraint = FilterUtils[filterMatchMode];
|
|
|
|
|
|
|
|
return filterConstraint(dataFieldValue, filterValue, this.filterLocale);
|
|
|
|
},
|
2019-11-18 11:52:17 +00:00
|
|
|
onRowClick(e) {
|
|
|
|
const event = e.originalEvent;
|
2020-05-02 09:19:17 +00:00
|
|
|
if (DomHandler.isClickable(event.target)) {
|
2019-11-20 09:56:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-11-18 11:52:17 +00:00
|
|
|
|
2019-12-04 07:19:48 +00:00
|
|
|
this.$emit('row-click', e);
|
2019-11-20 09:58:32 +00:00
|
|
|
|
2019-07-03 10:07:57 +00:00
|
|
|
if (this.selectionMode) {
|
2019-11-20 09:56:44 +00:00
|
|
|
const rowData = e.data;
|
|
|
|
const rowIndex = e.index;
|
2019-07-03 10:07:57 +00:00
|
|
|
|
|
|
|
if (this.isMultipleSelectionMode() && event.shiftKey && this.anchorRowIndex != null) {
|
|
|
|
DomHandler.clearSelection();
|
2019-07-09 09:37:19 +00:00
|
|
|
this.rangeRowIndex = rowIndex;
|
2019-07-09 09:57:21 +00:00
|
|
|
this.selectRange(event);
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const selected = this.isSelected(rowData);
|
|
|
|
const metaSelection = this.rowTouched ? false : this.metaKeySelection;
|
2019-07-09 09:37:19 +00:00
|
|
|
this.anchorRowIndex = rowIndex;
|
|
|
|
this.rangeRowIndex = rowIndex;
|
2019-07-03 10:07:57 +00:00
|
|
|
|
|
|
|
if (metaSelection) {
|
|
|
|
let metaKey = event.metaKey || event.ctrlKey;
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-03 10:07:57 +00:00
|
|
|
if (selected && metaKey) {
|
|
|
|
if(this.isSingleSelectionMode()) {
|
|
|
|
this.$emit('update:selection', null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const selectionIndex = this.findIndexInSelection(rowData);
|
|
|
|
const _selection = this.selection.filter((val,i) => i != selectionIndex);
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-12-09 08:37:20 +00:00
|
|
|
this.$emit('row-unselect', {originalEvent: event, data: rowData, index: event.index, type: 'row'});
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(this.isSingleSelectionMode()) {
|
|
|
|
this.$emit('update:selection', rowData);
|
|
|
|
}
|
|
|
|
else if (this.isMultipleSelectionMode()) {
|
|
|
|
let _selection = metaKey ? (this.selection || []) : [];
|
|
|
|
_selection = [..._selection, rowData];
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
}
|
|
|
|
|
2019-12-09 08:37:20 +00:00
|
|
|
this.$emit('row-select', {originalEvent: event, data: rowData, index: event.index, type: 'row'});
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (this.selectionMode === 'single') {
|
|
|
|
if (selected) {
|
|
|
|
this.$emit('update:selection', null);
|
2019-12-09 08:37:20 +00:00
|
|
|
this.$emit('row-unselect', {originalEvent: event, data: rowData, index: event.index, type: 'row'});
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$emit('update:selection', rowData);
|
2019-12-09 08:37:20 +00:00
|
|
|
this.$emit('row-select', {originalEvent: event, data: rowData, index: event.index, type: 'row'});
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.selectionMode === 'multiple') {
|
|
|
|
if (selected) {
|
|
|
|
const selectionIndex = this.findIndexInSelection(rowData);
|
|
|
|
const _selection = this.selection.filter((val, i) => i != selectionIndex);
|
|
|
|
this.$emit('update:selection', _selection);
|
2019-12-09 08:37:20 +00:00
|
|
|
this.$emit('row-unselect', {originalEvent: event, data: rowData, index: event.index, type: 'row'});
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const _selection = this.selection ? [...this.selection, rowData] : [rowData];
|
|
|
|
this.$emit('update:selection', _selection);
|
2019-12-09 08:37:20 +00:00
|
|
|
this.$emit('row-select', {originalEvent: event, data: rowData, index: event.index, type: 'row'});
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-03 10:07:57 +00:00
|
|
|
this.rowTouched = false;
|
|
|
|
},
|
2019-12-09 08:34:31 +00:00
|
|
|
onRowRightClick(event) {
|
|
|
|
DomHandler.clearSelection();
|
2020-04-07 12:29:31 +00:00
|
|
|
event.originalEvent.target.focus();
|
2019-12-09 08:34:31 +00:00
|
|
|
|
|
|
|
this.$emit('update:contextMenuSelection', event.data);
|
|
|
|
this.$emit('row-contextmenu', event);
|
|
|
|
},
|
2019-07-03 10:07:57 +00:00
|
|
|
onRowTouchEnd() {
|
|
|
|
this.rowTouched = true;
|
|
|
|
},
|
2019-11-18 11:52:17 +00:00
|
|
|
onRowKeyDown(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const rowData = e.data;
|
|
|
|
const rowIndex = e.index;
|
|
|
|
|
2019-07-09 09:44:46 +00:00
|
|
|
if (this.selectionMode) {
|
|
|
|
const row = event.target;
|
|
|
|
|
|
|
|
switch (event.which) {
|
|
|
|
//down arrow
|
|
|
|
case 40:
|
2019-07-09 09:57:21 +00:00
|
|
|
var nextRow = this.findNextSelectableRow(row);
|
2019-07-09 09:44:46 +00:00
|
|
|
if (nextRow) {
|
|
|
|
nextRow.focus();
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:44:46 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:44:46 +00:00
|
|
|
//up arrow
|
|
|
|
case 38:
|
2019-07-09 09:57:21 +00:00
|
|
|
var prevRow = this.findPrevSelectableRow(row);
|
2019-07-09 09:44:46 +00:00
|
|
|
if (prevRow) {
|
|
|
|
prevRow.focus();
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:44:46 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:44:46 +00:00
|
|
|
//enter
|
|
|
|
case 13:
|
2019-12-30 10:28:36 +00:00
|
|
|
this.onRowClick({originalEvent: event, data: rowData, index: rowIndex});
|
2019-07-09 09:44:46 +00:00
|
|
|
break;
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:44:46 +00:00
|
|
|
default:
|
|
|
|
//no op
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
findNextSelectableRow(row) {
|
|
|
|
let nextRow = row.nextElementSibling;
|
|
|
|
if (nextRow) {
|
2020-07-18 11:31:49 +00:00
|
|
|
if (DomHandler.hasClass(nextRow, 'p-selectable-row'))
|
2019-07-09 09:44:46 +00:00
|
|
|
return nextRow;
|
|
|
|
else
|
|
|
|
return this.findNextSelectableRow(nextRow);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
findPrevSelectableRow(row) {
|
|
|
|
let prevRow = row.previousElementSibling;
|
|
|
|
if (prevRow) {
|
2020-07-18 11:31:49 +00:00
|
|
|
if (DomHandler.hasClass(prevRow, 'p-selectable-row'))
|
2019-07-09 09:44:46 +00:00
|
|
|
return prevRow;
|
|
|
|
else
|
|
|
|
return this.findPrevSelectableRow(prevRow);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2019-07-09 11:36:24 +00:00
|
|
|
toggleRowWithRadio(event) {
|
|
|
|
const rowData = event.data;
|
|
|
|
|
|
|
|
if (this.isSelected(rowData)) {
|
|
|
|
this.$emit('update:selection', null);
|
|
|
|
this.$emit('row-unselect', {originalEvent: event, data: rowData, type: 'radiobutton'});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$emit('update:selection', rowData);
|
|
|
|
this.$emit('row-select', {originalEvent: event, data: rowData, type: 'radiobutton'});
|
|
|
|
}
|
|
|
|
},
|
2019-07-09 12:41:15 +00:00
|
|
|
toggleRowWithCheckbox(event) {
|
|
|
|
const rowData = event.data;
|
|
|
|
|
|
|
|
if (this.isSelected(rowData)) {
|
|
|
|
const selectionIndex = this.findIndexInSelection(rowData);
|
|
|
|
const _selection = this.selection.filter((val, i) => i != selectionIndex);
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
this.$emit('row-unselect', {originalEvent: event, data: rowData, type: 'checkbox'});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let _selection = this.selection ? [...this.selection] : [];
|
|
|
|
_selection = [..._selection, rowData];
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
this.$emit('row-select', {originalEvent: event, data: rowData, type: 'checkbox'});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleRowsWithCheckbox(event) {
|
|
|
|
const processedData = this.processedData;
|
|
|
|
const checked = this.allRowsSelected;
|
|
|
|
const _selection = checked ? [] : (processedData ? [...processedData] : [...this.value]);
|
|
|
|
this.$emit('update:selection', _selection);
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 12:41:15 +00:00
|
|
|
if (checked)
|
|
|
|
this.$emit('row-unselect-all', {originalEvent: event});
|
|
|
|
else
|
|
|
|
this.$emit('row-select-all', {originalEvent: event, data: _selection});
|
|
|
|
},
|
2019-07-03 10:07:57 +00:00
|
|
|
isSingleSelectionMode() {
|
|
|
|
return this.selectionMode === 'single';
|
|
|
|
},
|
|
|
|
isMultipleSelectionMode() {
|
|
|
|
return this.selectionMode === 'multiple';
|
|
|
|
},
|
|
|
|
isSelected(rowData) {
|
|
|
|
if (rowData && this.selection) {
|
|
|
|
if (this.dataKey) {
|
2019-07-09 09:44:46 +00:00
|
|
|
return this.d_selectionKeys ? this.d_selectionKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined : false;
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (this.selection instanceof Array)
|
|
|
|
return this.findIndexInSelection(rowData) > -1;
|
|
|
|
else
|
|
|
|
return this.equals(rowData, this.selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
findIndexInSelection(rowData) {
|
2019-10-21 06:21:15 +00:00
|
|
|
return this.findIndex(rowData, this.selection);
|
|
|
|
},
|
|
|
|
findIndex(rowData, collection) {
|
2019-07-03 10:07:57 +00:00
|
|
|
let index = -1;
|
2019-10-21 06:21:15 +00:00
|
|
|
if (collection && collection.length) {
|
|
|
|
for (let i = 0; i < collection.length; i++) {
|
|
|
|
if (this.equals(rowData, collection[i])) {
|
2019-07-03 10:07:57 +00:00
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
updateSelectionKeys(selection) {
|
|
|
|
this.d_selectionKeys = {};
|
|
|
|
if (Array.isArray(selection)) {
|
|
|
|
for (let data of selection) {
|
|
|
|
this.d_selectionKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.d_selectionKeys[String(ObjectUtils.resolveFieldData(selection, this.dataKey))] = 1;
|
|
|
|
}
|
|
|
|
},
|
2019-10-21 06:21:15 +00:00
|
|
|
updateExpandedRowKeys(expandedRows) {
|
|
|
|
if (expandedRows && expandedRows.length) {
|
|
|
|
this.d_expandedRowKeys = {};
|
|
|
|
for (let data of expandedRows) {
|
|
|
|
this.d_expandedRowKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.d_expandedRowKeys = null;
|
|
|
|
}
|
|
|
|
},
|
2019-10-30 11:58:57 +00:00
|
|
|
updateEditingRowKeys(editingRows) {
|
|
|
|
if (editingRows && editingRows.length) {
|
|
|
|
this.d_editingRowKeys = {};
|
|
|
|
for (let data of editingRows) {
|
|
|
|
this.d_editingRowKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.d_editingRowKeys = null;
|
|
|
|
}
|
|
|
|
},
|
2019-07-03 10:07:57 +00:00
|
|
|
equals(data1, data2) {
|
|
|
|
return this.compareSelectionBy === 'equals' ? (data1 === data2) : ObjectUtils.equals(data1, data2, this.dataKey);
|
|
|
|
},
|
2019-07-09 09:57:21 +00:00
|
|
|
selectRange(event) {
|
2019-07-09 09:37:19 +00:00
|
|
|
let rangeStart, rangeEnd;
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:37:19 +00:00
|
|
|
if (this.rangeRowIndex > this.anchorRowIndex) {
|
|
|
|
rangeStart = this.anchorRowIndex;
|
|
|
|
rangeEnd = this.rangeRowIndex;
|
|
|
|
}
|
|
|
|
else if(this.rangeRowIndex < this.anchorRowIndex) {
|
|
|
|
rangeStart = this.rangeRowIndex;
|
|
|
|
rangeEnd = this.anchorRowIndex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rangeStart = this.rangeRowIndex;
|
|
|
|
rangeEnd = this.rangeRowIndex;
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 09:37:19 +00:00
|
|
|
if (this.lazy && this.paginator) {
|
|
|
|
rangeStart -= this.first;
|
|
|
|
rangeEnd -= this.first;
|
|
|
|
}
|
|
|
|
|
2019-07-09 12:41:15 +00:00
|
|
|
const value = this.processedData;
|
2019-07-09 09:37:19 +00:00
|
|
|
let _selection = [];
|
|
|
|
for(let i = rangeStart; i <= rangeEnd; i++) {
|
2019-07-09 12:41:15 +00:00
|
|
|
let rangeRowData = value[i];
|
2019-07-09 09:37:19 +00:00
|
|
|
_selection.push(rangeRowData);
|
|
|
|
this.$emit('row-select', {originalEvent: event, data: rangeRowData, type: 'row'});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('update:selection', _selection);
|
2019-07-09 13:21:42 +00:00
|
|
|
},
|
|
|
|
exportCSV(options) {
|
|
|
|
let data = this.processedData;
|
|
|
|
let csv = '\ufeff';
|
|
|
|
|
|
|
|
if (options && options.selectionOnly) {
|
|
|
|
data = this.selection || [];
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-07-09 13:21:42 +00:00
|
|
|
//headers
|
2020-09-24 08:55:27 +00:00
|
|
|
let headerInitiated = false;
|
2019-07-09 13:21:42 +00:00
|
|
|
for (let i = 0; i < this.columns.length; i++) {
|
|
|
|
let column = this.columns[i];
|
2020-09-27 18:29:11 +00:00
|
|
|
|
2021-02-02 13:21:10 +00:00
|
|
|
if (this.columnProp(column, 'exportable') !== false && this.columnProp(column, 'field')) {
|
2020-09-27 18:29:11 +00:00
|
|
|
if (headerInitiated)
|
2019-07-09 13:21:42 +00:00
|
|
|
csv += this.csvSeparator;
|
2020-09-24 08:55:27 +00:00
|
|
|
else
|
|
|
|
headerInitiated = true;
|
|
|
|
|
2021-02-02 13:21:10 +00:00
|
|
|
csv += '"' + (this.columnProp(column, 'header') || this.columnProp(column, 'field')) + '"';
|
2019-07-09 13:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//body
|
2020-08-04 12:46:23 +00:00
|
|
|
if (data) {
|
|
|
|
data.forEach(record => {
|
|
|
|
csv += '\n';
|
2020-09-24 08:55:27 +00:00
|
|
|
let rowInitiated = false;
|
2020-08-04 12:46:23 +00:00
|
|
|
for (let i = 0; i < this.columns.length; i++) {
|
|
|
|
let column = this.columns[i];
|
2021-02-02 13:21:10 +00:00
|
|
|
if (this.columnProp(column, 'exportable') !== false && this.columnProp(column, 'field')) {
|
2020-09-27 18:29:11 +00:00
|
|
|
if (rowInitiated)
|
2020-09-24 08:55:27 +00:00
|
|
|
csv += this.csvSeparator;
|
|
|
|
else
|
|
|
|
rowInitiated = true;
|
|
|
|
|
2021-02-02 13:21:10 +00:00
|
|
|
let cellData = ObjectUtils.resolveFieldData(record, this.columnProp(column, 'field'));
|
2020-08-04 12:58:15 +00:00
|
|
|
|
2020-08-04 12:46:23 +00:00
|
|
|
if (cellData != null) {
|
|
|
|
if (this.exportFunction) {
|
|
|
|
cellData = this.exportFunction({
|
|
|
|
data: cellData,
|
2021-02-02 13:21:10 +00:00
|
|
|
field: this.columnProp(column, 'field')
|
2020-08-04 12:46:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cellData = String(cellData).replace(/"/g, '""');
|
2019-07-09 13:21:42 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-04 12:46:23 +00:00
|
|
|
cellData = '';
|
2020-08-04 12:58:15 +00:00
|
|
|
|
2020-08-04 12:46:23 +00:00
|
|
|
csv += '"' + cellData + '"';
|
2019-07-09 13:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-04 12:46:23 +00:00
|
|
|
});
|
|
|
|
}
|
2019-07-09 13:21:42 +00:00
|
|
|
|
|
|
|
let blob = new Blob([csv], {
|
|
|
|
type: 'text/csv;charset=utf-8;'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
navigator.msSaveOrOpenBlob(blob, this.exportFilename + '.csv');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let link = document.createElement("a");
|
|
|
|
link.style.display = 'none';
|
|
|
|
document.body.appendChild(link);
|
|
|
|
if (link.download !== undefined) {
|
|
|
|
link.setAttribute('href', URL.createObjectURL(blob));
|
|
|
|
link.setAttribute('download', this.exportFilename + '.csv');
|
|
|
|
link.click();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
csv = 'data:text/csv;charset=utf-8,' + csv;
|
|
|
|
window.open(encodeURI(csv));
|
|
|
|
}
|
|
|
|
document.body.removeChild(link);
|
|
|
|
}
|
2019-07-28 14:11:23 +00:00
|
|
|
},
|
|
|
|
resetPage() {
|
|
|
|
this.d_first = 0;
|
|
|
|
this.$emit('update:first', this.d_first);
|
2019-08-07 13:50:07 +00:00
|
|
|
},
|
|
|
|
onColumnResizeStart(event) {
|
|
|
|
let containerLeft = DomHandler.getOffset(this.$el).left;
|
|
|
|
this.resizeColumnElement = event.target.parentElement;
|
|
|
|
this.columnResizing = true;
|
|
|
|
this.lastResizeHelperX = (event.pageX - containerLeft + this.$el.scrollLeft);
|
|
|
|
|
|
|
|
this.bindColumnResizeEvents();
|
|
|
|
},
|
|
|
|
onColumnResize(event) {
|
|
|
|
let containerLeft = DomHandler.getOffset(this.$el).left;
|
|
|
|
DomHandler.addClass(this.$el, 'p-unselectable-text');
|
|
|
|
this.$refs.resizeHelper.style.height = this.$el.offsetHeight + 'px';
|
|
|
|
this.$refs.resizeHelper.style.top = 0 + 'px';
|
|
|
|
this.$refs.resizeHelper.style.left = (event.pageX - containerLeft + this.$el.scrollLeft) + 'px';
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-08-07 13:50:07 +00:00
|
|
|
this.$refs.resizeHelper.style.display = 'block';
|
|
|
|
},
|
2019-08-07 13:51:43 +00:00
|
|
|
onColumnResizeEnd() {
|
2019-08-07 13:50:07 +00:00
|
|
|
let delta = this.$refs.resizeHelper.offsetLeft - this.lastResizeHelperX;
|
|
|
|
let columnWidth = this.resizeColumnElement.offsetWidth;
|
|
|
|
let newColumnWidth = columnWidth + delta;
|
|
|
|
let minWidth = this.resizeColumnElement.style.minWidth||15;
|
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
if (columnWidth + delta > parseInt(minWidth, 10)) {
|
|
|
|
if (this.columnResizeMode === 'fit') {
|
2019-08-07 13:50:07 +00:00
|
|
|
let nextColumn = this.resizeColumnElement.nextElementSibling;
|
|
|
|
let nextColumnWidth = nextColumn.offsetWidth - delta;
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
if (newColumnWidth > 15 && nextColumnWidth > 15) {
|
|
|
|
if(this.scrollable) {
|
|
|
|
const scrollableView = this.findParentScrollableView(this.resizeColumnElement);
|
|
|
|
const scrollableBodyTable = DomHandler.findSingle(scrollableView, 'table.p-datatable-scrollable-body-table');
|
|
|
|
const scrollableHeaderTable = DomHandler.findSingle(scrollableView, 'table.p-datatable-scrollable-header-table');
|
|
|
|
const scrollableFooterTable = DomHandler.findSingle(scrollableView, 'table.p-datatable-scrollable-footer-table');
|
|
|
|
const resizeColumnIndex = DomHandler.index(this.resizeColumnElement);
|
|
|
|
|
|
|
|
this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
|
|
|
|
this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
|
|
|
|
this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.resizeColumnElement.style.width = newColumnWidth + 'px';
|
|
|
|
if(nextColumn) {
|
|
|
|
nextColumn.style.width = nextColumnWidth + 'px';
|
2019-11-19 14:05:22 +00:00
|
|
|
}
|
2019-08-07 13:50:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 13:21:39 +00:00
|
|
|
else if (this.columnResizeMode === 'expand') {
|
|
|
|
if (this.scrollable) {
|
|
|
|
this.resizeScrollableTable(this.resizeColumnElement, newColumnWidth, delta);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$refs.table.style.width = this.$refs.table.offsetWidth + delta + 'px';
|
|
|
|
this.resizeColumnElement.style.width = newColumnWidth + 'px';
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 13:50:07 +00:00
|
|
|
this.$emit('column-resize-end', {
|
|
|
|
element: this.resizeColumnElement,
|
|
|
|
delta: delta
|
|
|
|
});
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-08-07 13:50:07 +00:00
|
|
|
this.$refs.resizeHelper.style.display = 'none';
|
|
|
|
this.resizeColumn = null;
|
|
|
|
DomHandler.removeClass(this.$el, 'p-unselectable-text');
|
|
|
|
|
|
|
|
this.unbindColumnResizeEvents();
|
2019-10-22 07:36:04 +00:00
|
|
|
|
|
|
|
if (this.isStateful()) {
|
|
|
|
this.saveState();
|
|
|
|
}
|
2019-08-07 13:50:07 +00:00
|
|
|
},
|
2019-11-19 13:21:39 +00:00
|
|
|
resizeColGroup(table, resizeColumnIndex, newColumnWidth, nextColumnWidth) {
|
|
|
|
if(table) {
|
|
|
|
let colGroup = table.children[0].nodeName === 'COLGROUP' ? table.children[0] : null;
|
|
|
|
|
|
|
|
if(colGroup) {
|
|
|
|
let col = colGroup.children[resizeColumnIndex];
|
|
|
|
let nextCol = col.nextElementSibling;
|
|
|
|
col.style.width = newColumnWidth + 'px';
|
2019-11-19 14:05:22 +00:00
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
if (nextCol && nextColumnWidth) {
|
|
|
|
nextCol.style.width = nextColumnWidth + 'px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new Error("Scrollable tables require a colgroup to support resizable columns");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-08-07 13:50:07 +00:00
|
|
|
bindColumnResizeEvents() {
|
|
|
|
if (!this.documentColumnResizeListener) {
|
2019-08-07 16:49:04 +00:00
|
|
|
this.documentColumnResizeListener = document.addEventListener('mousemove', () => {
|
2019-08-07 13:50:07 +00:00
|
|
|
if(this.columnResizing) {
|
|
|
|
this.onColumnResize(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-08-07 13:50:07 +00:00
|
|
|
if (!this.documentColumnResizeEndListener) {
|
2019-08-07 16:49:04 +00:00
|
|
|
this.documentColumnResizeEndListener = document.addEventListener('mouseup', () => {
|
2019-08-07 13:50:07 +00:00
|
|
|
if(this.columnResizing) {
|
|
|
|
this.columnResizing = false;
|
2019-08-07 13:51:43 +00:00
|
|
|
this.onColumnResizeEnd();
|
2019-08-07 13:50:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-08-07 13:50:07 +00:00
|
|
|
},
|
|
|
|
unbindColumnResizeEvents() {
|
|
|
|
if (this.documentColumnResizeListener) {
|
|
|
|
document.removeEventListener('document', this.documentColumnResizeListener);
|
|
|
|
this.documentColumnResizeListener = null;
|
|
|
|
}
|
2019-10-01 13:00:26 +00:00
|
|
|
|
2019-08-07 13:50:07 +00:00
|
|
|
if (this.documentColumnResizeEndListener) {
|
|
|
|
document.removeEventListener('document', this.documentColumnResizeEndListener);
|
|
|
|
this.documentColumnResizeEndListener = null;
|
|
|
|
}
|
2019-10-17 11:50:20 +00:00
|
|
|
},
|
2019-11-18 07:42:32 +00:00
|
|
|
onColumnHeaderMouseDown(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const column = e.column;
|
|
|
|
|
2021-02-02 13:21:10 +00:00
|
|
|
if (this.reorderableColumns && this.columnProp(column, 'reorderableColumn') !== false) {
|
2019-10-17 11:50:20 +00:00
|
|
|
if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA' || DomHandler.hasClass(event.target, 'p-column-resizer'))
|
|
|
|
event.currentTarget.draggable = false;
|
|
|
|
else
|
|
|
|
event.currentTarget.draggable = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderDragStart(event) {
|
2019-11-18 07:42:32 +00:00
|
|
|
if (this.columnResizing) {
|
2019-10-17 11:50:20 +00:00
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
this.colReorderIconWidth = DomHandler.getHiddenElementOuterWidth(this.$refs.reorderIndicatorUp);
|
|
|
|
this.colReorderIconHeight = DomHandler.getHiddenElementOuterHeight(this.$refs.reorderIndicatorUp);
|
|
|
|
|
|
|
|
this.draggedColumn = this.findParentHeader(event.target);
|
|
|
|
event.dataTransfer.setData('text', 'b'); // Firefox requires this to make dragging possible
|
|
|
|
},
|
|
|
|
onColumnHeaderDragOver(event) {
|
|
|
|
let dropHeader = this.findParentHeader(event.target);
|
|
|
|
if(this.reorderableColumns && this.draggedColumn && dropHeader) {
|
|
|
|
event.preventDefault();
|
|
|
|
let containerOffset = DomHandler.getOffset(this.$el);
|
|
|
|
let dropHeaderOffset = DomHandler.getOffset(dropHeader);
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
if (this.draggedColumn !== dropHeader) {
|
|
|
|
let targetLeft = dropHeaderOffset.left - containerOffset.left;
|
|
|
|
let columnCenter = dropHeaderOffset.left + dropHeader.offsetWidth / 2;
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
this.$refs.reorderIndicatorUp.style.top = dropHeaderOffset.top - containerOffset.top - (this.colReorderIconHeight - 1) + 'px';
|
|
|
|
this.$refs.reorderIndicatorDown.style.top = dropHeaderOffset.top - containerOffset.top + dropHeader.offsetHeight + 'px';
|
|
|
|
|
|
|
|
if(event.pageX > columnCenter) {
|
|
|
|
this.$refs.reorderIndicatorUp.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.colReorderIconWidth / 2)) + 'px';
|
|
|
|
this.$refs.reorderIndicatorDown.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.colReorderIconWidth / 2))+ 'px';
|
|
|
|
this.dropPosition = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$refs.reorderIndicatorUp.style.left = (targetLeft - Math.ceil(this.colReorderIconWidth / 2)) + 'px';
|
|
|
|
this.$refs.reorderIndicatorDown.style.left = (targetLeft - Math.ceil(this.colReorderIconWidth / 2))+ 'px';
|
|
|
|
this.dropPosition = -1;
|
|
|
|
}
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
this.$refs.reorderIndicatorUp.style.display = 'block';
|
|
|
|
this.$refs.reorderIndicatorDown.style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderDragLeave(event) {
|
|
|
|
if(this.reorderableColumns && this.draggedColumn) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.$refs.reorderIndicatorUp.style.display = 'none';
|
|
|
|
this.$refs.reorderIndicatorDown.style.display = 'none';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderDrop(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (this.draggedColumn) {
|
|
|
|
let dragIndex = DomHandler.index(this.draggedColumn);
|
|
|
|
let dropIndex = DomHandler.index(this.findParentHeader(event.target));
|
|
|
|
let allowDrop = (dragIndex !== dropIndex);
|
|
|
|
if (allowDrop && ((dropIndex - dragIndex === 1 && this.dropPosition === -1) || (dragIndex - dropIndex === 1 && this.dropPosition === 1))) {
|
|
|
|
allowDrop = false;
|
|
|
|
}
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
if (allowDrop) {
|
2019-10-22 07:36:04 +00:00
|
|
|
ObjectUtils.reorderArray(this.d_columnOrder, dragIndex, dropIndex);
|
2019-10-17 11:50:20 +00:00
|
|
|
|
2019-10-17 14:12:49 +00:00
|
|
|
this.$emit('column-reorder', {
|
|
|
|
originalEvent: event,
|
2019-10-17 11:50:20 +00:00
|
|
|
dragIndex: dragIndex,
|
2019-10-17 14:12:49 +00:00
|
|
|
dropIndex: dropIndex
|
2019-10-17 11:50:20 +00:00
|
|
|
});
|
|
|
|
}
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
this.$refs.reorderIndicatorUp.style.display = 'none';
|
|
|
|
this.$refs.reorderIndicatorDown.style.display = 'none';
|
|
|
|
this.draggedColumn.draggable = false;
|
|
|
|
this.draggedColumn = null;
|
|
|
|
this.dropPosition = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
findParentHeader(element) {
|
|
|
|
if(element.nodeName === 'TH') {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let parent = element.parentElement;
|
|
|
|
while(parent.nodeName !== 'TH') {
|
|
|
|
parent = parent.parentElement;
|
|
|
|
if (!parent) break;
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
},
|
2019-11-19 13:21:39 +00:00
|
|
|
findParentScrollableView(column) {
|
|
|
|
if (column) {
|
|
|
|
let parent = column.parentElement;
|
|
|
|
while (parent && !DomHandler.hasClass(parent, 'p-datatable-scrollable-view')) {
|
|
|
|
parent = parent.parentElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2019-10-17 11:50:20 +00:00
|
|
|
findColumnByKey(columns, key) {
|
2020-09-23 19:48:53 +00:00
|
|
|
if (columns && columns.length) {
|
|
|
|
for (let i = 0; i < columns.length; i++) {
|
|
|
|
let column = columns[i];
|
2021-02-02 13:21:10 +00:00
|
|
|
if (this.columnProp(column, 'columnKey') === key || this.columnProp(column, 'field') === key) {
|
2020-09-23 19:48:53 +00:00
|
|
|
return column;
|
2019-10-17 11:50:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 11:50:20 +00:00
|
|
|
return null;
|
2019-10-17 13:56:54 +00:00
|
|
|
},
|
2019-11-19 13:21:39 +00:00
|
|
|
resizeScrollableTable(column, newColumnWidth, delta) {
|
|
|
|
const scrollableView = column ? this.findParentScrollableView(column) : this.$el;
|
|
|
|
const scrollableBody = DomHandler.findSingle(scrollableView, '.p-datatable-scrollable-body');
|
|
|
|
const scrollableHeader = DomHandler.findSingle(scrollableView, '.p-datatable-scrollable-header');
|
|
|
|
const scrollableFooter = DomHandler.findSingle(scrollableView, '.p-datatable-scrollable-footer');
|
|
|
|
const scrollableBodyTable = DomHandler.findSingle(scrollableBody, 'table.p-datatable-scrollable-body-table');
|
|
|
|
const scrollableHeaderTable = DomHandler.findSingle(scrollableHeader, 'table.p-datatable-scrollable-header-table');
|
|
|
|
const scrollableFooterTable = DomHandler.findSingle(scrollableFooter, 'table.p-datatable-scrollable-footer-table');
|
|
|
|
|
|
|
|
const scrollableBodyTableWidth = column ? scrollableBodyTable.offsetWidth + delta : newColumnWidth;
|
|
|
|
const scrollableHeaderTableWidth = column ? scrollableHeaderTable.offsetWidth + delta : newColumnWidth;
|
|
|
|
const isContainerInViewport = this.$el.offsetWidth >= parseFloat(scrollableBodyTableWidth);
|
2019-11-19 14:05:22 +00:00
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
let setWidth = (container, table, width, isContainerInViewport) => {
|
|
|
|
if (container && table) {
|
|
|
|
container.style.width = isContainerInViewport ? width + DomHandler.calculateScrollbarWidth(scrollableBody) + 'px' : 'auto'
|
|
|
|
table.style.width = width + 'px';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
setWidth(scrollableBody, scrollableBodyTable, scrollableBodyTableWidth, isContainerInViewport);
|
|
|
|
setWidth(scrollableHeader, scrollableHeaderTable, scrollableHeaderTableWidth, isContainerInViewport);
|
|
|
|
setWidth(scrollableFooter, scrollableFooterTable, scrollableHeaderTableWidth, isContainerInViewport);
|
2019-11-19 14:05:22 +00:00
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
if (column) {
|
|
|
|
let resizeColumnIndex = DomHandler.index(column);
|
|
|
|
|
|
|
|
this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, null);
|
|
|
|
this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, null);
|
|
|
|
this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, null);
|
|
|
|
}
|
|
|
|
},
|
2019-10-17 13:56:54 +00:00
|
|
|
onRowMouseDown(event) {
|
|
|
|
if (DomHandler.hasClass(event.target, 'p-datatable-reorderablerow-handle'))
|
|
|
|
event.currentTarget.draggable = true;
|
|
|
|
else
|
|
|
|
event.currentTarget.draggable = false;
|
|
|
|
},
|
2019-11-18 11:52:17 +00:00
|
|
|
onRowDragStart(e) {
|
|
|
|
const event = e.originalEvent;
|
2019-11-18 12:09:29 +00:00
|
|
|
const index = e.index;
|
2019-10-17 13:56:54 +00:00
|
|
|
this.rowDragging = true;
|
|
|
|
this.draggedRowIndex = index;
|
|
|
|
event.dataTransfer.setData('text', 'b'); // For firefox
|
|
|
|
},
|
2019-11-18 11:52:17 +00:00
|
|
|
onRowDragOver(e) {
|
|
|
|
const event = e.originalEvent;
|
2019-11-18 12:09:29 +00:00
|
|
|
const index = e.index;
|
2019-11-18 11:52:17 +00:00
|
|
|
|
2019-10-17 13:56:54 +00:00
|
|
|
if (this.rowDragging && this.draggedRowIndex !== index) {
|
|
|
|
let rowElement = event.currentTarget;
|
|
|
|
let rowY = DomHandler.getOffset(rowElement).top + DomHandler.getWindowScrollTop();
|
|
|
|
let pageY = event.pageY;
|
|
|
|
let rowMidY = rowY + DomHandler.getOuterHeight(rowElement) / 2;
|
|
|
|
let prevRowElement = rowElement.previousElementSibling;
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 13:56:54 +00:00
|
|
|
if (pageY < rowMidY) {
|
|
|
|
DomHandler.removeClass(rowElement, 'p-datatable-dragpoint-bottom');
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 13:56:54 +00:00
|
|
|
this.droppedRowIndex = index;
|
|
|
|
if (prevRowElement)
|
|
|
|
DomHandler.addClass(prevRowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
else
|
|
|
|
DomHandler.addClass(rowElement, 'p-datatable-dragpoint-top');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (prevRowElement)
|
|
|
|
DomHandler.removeClass(prevRowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
else
|
|
|
|
DomHandler.addClass(rowElement, 'p-datatable-dragpoint-top');
|
2019-10-17 14:17:27 +00:00
|
|
|
|
2019-10-17 13:56:54 +00:00
|
|
|
this.droppedRowIndex = index + 1;
|
|
|
|
DomHandler.addClass(rowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onRowDragLeave(event) {
|
|
|
|
let rowElement = event.currentTarget;
|
|
|
|
let prevRowElement = rowElement.previousElementSibling;
|
|
|
|
if (prevRowElement) {
|
|
|
|
DomHandler.removeClass(prevRowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
}
|
|
|
|
|
|
|
|
DomHandler.removeClass(rowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
DomHandler.removeClass(rowElement, 'p-datatable-dragpoint-top');
|
|
|
|
},
|
|
|
|
onRowDragEnd(event) {
|
|
|
|
this.rowDragging = false;
|
|
|
|
this.draggedRowIndex = null;
|
|
|
|
this.droppedRowIndex = null;
|
|
|
|
event.currentTarget.draggable = false;
|
|
|
|
},
|
|
|
|
onRowDrop(event) {
|
|
|
|
if (this.droppedRowIndex != null) {
|
|
|
|
let dropIndex = (this.draggedRowIndex > this.droppedRowIndex) ? this.droppedRowIndex : (this.droppedRowIndex === 0) ? 0 : this.droppedRowIndex - 1;
|
|
|
|
let processedData = [...this.processedData];
|
|
|
|
ObjectUtils.reorderArray(processedData, this.draggedRowIndex, dropIndex);
|
|
|
|
|
|
|
|
this.$emit('row-reorder', {
|
2019-10-17 14:12:49 +00:00
|
|
|
originalEvent: event,
|
2019-10-17 13:56:54 +00:00
|
|
|
dragIndex: this.draggedRowIndex,
|
|
|
|
dropIndex: dropIndex,
|
|
|
|
value: processedData
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
this.onRowDragLeave(event);
|
|
|
|
this.onRowDragEnd(event);
|
|
|
|
event.preventDefault();
|
2019-10-21 06:21:15 +00:00
|
|
|
},
|
2019-10-21 08:50:13 +00:00
|
|
|
toggleRow(event) {
|
|
|
|
let rowData = event.data;
|
2019-10-21 06:21:15 +00:00
|
|
|
let expanded;
|
|
|
|
let expandedRowIndex;
|
|
|
|
let _expandedRows = this.expandedRows ? [...this.expandedRows] : [];
|
|
|
|
|
|
|
|
if (this.dataKey) {
|
|
|
|
expanded = this.d_expandedRowKeys ? this.d_expandedRowKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined : false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
expandedRowIndex = this.findIndex(rowData, this.expandedRows);
|
|
|
|
expanded = expandedRowIndex > -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expanded) {
|
|
|
|
if (expandedRowIndex == null) {
|
|
|
|
expandedRowIndex = this.findIndex(rowData, this.expandedRows);
|
|
|
|
}
|
|
|
|
_expandedRows.splice(expandedRowIndex, 1);
|
|
|
|
this.$emit('update:expandedRows', _expandedRows);
|
2019-10-21 08:50:13 +00:00
|
|
|
this.$emit('row-collapse', event);
|
2019-10-21 06:21:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_expandedRows.push(rowData);
|
|
|
|
this.$emit('update:expandedRows', _expandedRows);
|
2019-10-21 08:50:13 +00:00
|
|
|
this.$emit('row-expand', event);
|
2019-10-21 06:21:15 +00:00
|
|
|
}
|
|
|
|
},
|
2019-11-18 11:52:17 +00:00
|
|
|
toggleRowGroup(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const data = e.data;
|
|
|
|
const groupFieldValue = ObjectUtils.resolveFieldData(data, this.groupRowsBy);
|
2019-10-21 14:20:06 +00:00
|
|
|
let _expandedRowGroups = this.expandedRowGroups ? [...this.expandedRowGroups] : [];
|
|
|
|
|
|
|
|
if (this.isRowGroupExpanded(data)) {
|
|
|
|
_expandedRowGroups = _expandedRowGroups.filter(group => group !== groupFieldValue);
|
|
|
|
this.$emit('update:expandedRowGroups', _expandedRowGroups);
|
|
|
|
this.$emit('rowgroup-collapse', {originalEvent: event, data: groupFieldValue});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_expandedRowGroups.push(groupFieldValue);
|
|
|
|
this.$emit('update:expandedRowGroups', _expandedRowGroups);
|
|
|
|
this.$emit('rowgroup-expand', {originalEvent: event, data: groupFieldValue});
|
|
|
|
}
|
|
|
|
},
|
2019-11-18 13:26:37 +00:00
|
|
|
isRowGroupExpanded(rowData) {
|
|
|
|
if (this.expandableRowGroups && this.expandedRowGroups) {
|
|
|
|
let groupFieldValue = ObjectUtils.resolveFieldData(rowData, this.groupRowsBy);
|
|
|
|
return this.expandedRowGroups.indexOf(groupFieldValue) > -1;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2019-10-22 07:36:04 +00:00
|
|
|
isStateful() {
|
|
|
|
return this.stateKey != null;
|
|
|
|
},
|
|
|
|
getStorage() {
|
|
|
|
switch(this.stateStorage) {
|
|
|
|
case 'local':
|
|
|
|
return window.localStorage;
|
|
|
|
|
|
|
|
case 'session':
|
|
|
|
return window.sessionStorage;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Error(this.stateStorage + ' is not a valid value for the state storage, supported values are "local" and "session".');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
saveState() {
|
|
|
|
const storage = this.getStorage();
|
|
|
|
let state = {};
|
|
|
|
|
|
|
|
if (this.paginator) {
|
|
|
|
state.first = this.d_first;
|
|
|
|
state.rows = this.d_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.d_sortField) {
|
|
|
|
state.sortField = this.d_sortField;
|
|
|
|
state.sortOrder = this.d_sortOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.d_multiSortMeta) {
|
|
|
|
state.multiSortMeta = this.d_multiSortMeta;
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:33:51 +00:00
|
|
|
if (this.hasFilters()) {
|
2019-10-22 07:36:04 +00:00
|
|
|
state.filters = this.filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.resizableColumns) {
|
|
|
|
this.saveColumnWidths(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.reorderableColumns) {
|
|
|
|
state.columnOrder = this.d_columnOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.expandedRows) {
|
|
|
|
state.expandedRows = this.expandedRows;
|
|
|
|
state.expandedRowKeys = this.d_expandedRowKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.expandedRowGroups) {
|
|
|
|
state.expandedRowGroups = this.expandedRowGroups;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selection) {
|
|
|
|
state.selection = this.selection;
|
|
|
|
state.selectionKeys = this.d_selectionKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object.keys(state).length) {
|
|
|
|
storage.setItem(this.stateKey, JSON.stringify(state));
|
|
|
|
}
|
2021-01-20 09:37:50 +00:00
|
|
|
|
|
|
|
this.$emit('state-save', state);
|
2019-10-22 07:36:04 +00:00
|
|
|
},
|
|
|
|
restoreState() {
|
|
|
|
const storage = this.getStorage();
|
|
|
|
const stateString = storage.getItem(this.stateKey);
|
|
|
|
|
|
|
|
if (stateString) {
|
|
|
|
let restoredState = JSON.parse(stateString);
|
|
|
|
|
|
|
|
if (this.paginator) {
|
|
|
|
this.d_first = restoredState.first;
|
|
|
|
this.d_rows = restoredState.rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restoredState.sortField) {
|
|
|
|
this.d_sortField = restoredState.sortField;
|
|
|
|
this.d_sortOrder = restoredState.sortOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restoredState.multiSortMeta) {
|
|
|
|
this.d_multiSortMeta = restoredState.multiSortMeta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restoredState.filters) {
|
|
|
|
this.$emit('update:filters', restoredState.filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.resizableColumns) {
|
|
|
|
this.columnWidthsState = restoredState.columnWidths;
|
|
|
|
this.tableWidthState = restoredState.tableWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.reorderableColumns) {
|
|
|
|
this.d_columnOrder = restoredState.columnOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restoredState.expandedRows) {
|
|
|
|
this.d_expandedRowKeys = restoredState.expandedRowKeys;
|
|
|
|
this.$emit('update:expandedRows', restoredState.expandedRows);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restoredState.expandedRowGroups) {
|
|
|
|
this.$emit('update:expandedRowGroups', restoredState.expandedRowGroups);
|
|
|
|
}
|
|
|
|
|
2019-10-22 07:58:07 +00:00
|
|
|
if (restoredState.selection) {
|
2019-10-22 07:36:04 +00:00
|
|
|
this.d_selectionKeys = restoredState.d_selectionKeys;
|
2019-10-22 07:58:07 +00:00
|
|
|
this.$emit('update:selection', restoredState.selection);
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
2021-01-20 09:37:50 +00:00
|
|
|
|
|
|
|
this.$emit('state-restore', restoredState);
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
saveColumnWidths(state) {
|
|
|
|
let widths = [];
|
|
|
|
let headers = DomHandler.find(this.$el, '.p-datatable-thead > tr > th');
|
|
|
|
headers.forEach(header => widths.push(DomHandler.getOuterWidth(header)));
|
|
|
|
state.columnWidths = widths.join(',');
|
|
|
|
|
|
|
|
if (this.columnResizeMode === 'expand') {
|
2019-11-19 13:21:39 +00:00
|
|
|
state.tableWidth = this.scrollable ? DomHandler.findSingle(this.$el, '.p-datatable-scrollable-header-table').style.width :
|
|
|
|
DomHandler.getOuterWidth(this.$refs.table) + 'px';
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
restoreColumnWidths() {
|
|
|
|
if (this.columnWidthsState) {
|
|
|
|
let widths = this.columnWidthsState.split(',');
|
|
|
|
|
|
|
|
if (this.columnResizeMode === 'expand' && this.tableWidthState) {
|
2019-11-19 13:21:39 +00:00
|
|
|
if (this.scrollable) {
|
|
|
|
this.resizeScrollableTable(null, this.tableWidthState, 0);
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$refs.table.style.width = this.tableWidthState;
|
|
|
|
this.$el.style.width = this.tableWidthState;
|
2019-11-19 13:21:39 +00:00
|
|
|
}
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
2019-11-19 14:05:22 +00:00
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
if (this.scrollable) {
|
|
|
|
let headerCols = DomHandler.find(this.$el, '.p-datatable-scrollable-header-table > colgroup > col');
|
|
|
|
let bodyCols = DomHandler.find(this.$el, '.p-datatable-scrollable-body-table > colgroup > col');
|
2019-10-22 07:36:04 +00:00
|
|
|
|
2019-11-19 13:21:39 +00:00
|
|
|
headerCols.forEach((col, index) => col.style.width = widths[index] + 'px');
|
|
|
|
bodyCols.forEach((col, index) => col.style.width = widths[index] + 'px');
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-19 13:21:39 +00:00
|
|
|
let headers = DomHandler.find(this.$refs.table, '.p-datatable-thead > tr > th');
|
|
|
|
headers.forEach((header, index) => header.style.width = widths[index] + 'px');
|
|
|
|
}
|
|
|
|
|
2019-11-19 14:05:22 +00:00
|
|
|
|
2019-10-22 07:36:04 +00:00
|
|
|
}
|
2019-10-30 10:32:46 +00:00
|
|
|
},
|
2019-10-30 11:58:57 +00:00
|
|
|
onCellEditInit(event) {
|
|
|
|
this.$emit('cell-edit-init', event);
|
|
|
|
},
|
|
|
|
onCellEditComplete(event) {
|
|
|
|
this.$emit('cell-edit-complete', event);
|
2019-10-30 10:32:46 +00:00
|
|
|
},
|
2019-10-30 11:58:57 +00:00
|
|
|
onCellEditCancel(event) {
|
|
|
|
this.$emit('cell-edit-cancel', event);
|
|
|
|
},
|
|
|
|
onRowEditInit(event) {
|
|
|
|
let _editingRows = this.editingRows ? [...this.editingRows] : [];
|
|
|
|
_editingRows.push(event.data);
|
|
|
|
this.$emit('update:editingRows', _editingRows);
|
2019-11-01 08:35:39 +00:00
|
|
|
this.$emit('row-edit-init', event);
|
2019-10-30 11:58:57 +00:00
|
|
|
},
|
|
|
|
onRowEditSave(event) {
|
|
|
|
let _editingRows = [...this.editingRows];
|
2020-01-30 08:41:28 +00:00
|
|
|
_editingRows.splice(this.findIndex(event.data, _editingRows), 1);
|
2019-10-30 11:58:57 +00:00
|
|
|
this.$emit('update:editingRows', _editingRows);
|
|
|
|
this.$emit('row-edit-save', event);
|
|
|
|
},
|
|
|
|
onRowEditCancel(event) {
|
|
|
|
let _editingRows = [...this.editingRows];
|
2020-01-30 08:41:28 +00:00
|
|
|
_editingRows.splice(this.findIndex(event.data, _editingRows), 1);
|
2019-10-30 11:58:57 +00:00
|
|
|
this.$emit('update:editingRows', _editingRows);
|
|
|
|
this.$emit('row-edit-cancel', event);
|
2019-11-19 11:54:24 +00:00
|
|
|
},
|
|
|
|
onVirtualScroll(event) {
|
|
|
|
if(this.virtualScrollTimer) {
|
|
|
|
clearTimeout(this.virtualScrollTimer);
|
|
|
|
}
|
2019-11-19 12:23:01 +00:00
|
|
|
|
2019-11-19 11:54:24 +00:00
|
|
|
this.virtualScrollTimer = setTimeout(() => {
|
|
|
|
this.$emit('virtual-scroll', {
|
|
|
|
first: (event.page - 1) * this.rows,
|
|
|
|
rows: this.rows * 2
|
|
|
|
});
|
|
|
|
}, this.virtualScrollDelay);
|
2020-01-30 09:06:16 +00:00
|
|
|
},
|
|
|
|
createLazyLoadEvent(event) {
|
2020-02-07 07:23:19 +00:00
|
|
|
let filterMatchModes;
|
2020-11-25 10:33:51 +00:00
|
|
|
if (this.hasFilters()) {
|
2020-02-07 07:23:19 +00:00
|
|
|
filterMatchModes = {};
|
|
|
|
this.columns.forEach(col => {
|
|
|
|
if (col.field) {
|
|
|
|
filterMatchModes[col.field] = col.filterMatchMode;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-30 09:06:16 +00:00
|
|
|
return {
|
|
|
|
originalEvent: event,
|
|
|
|
first: this.d_first,
|
|
|
|
rows: this.d_rows,
|
|
|
|
sortField: this.d_sortField,
|
|
|
|
sortOrder: this.d_sortOrder,
|
2020-02-07 07:23:19 +00:00
|
|
|
multiSortMeta: this.d_multiSortMeta,
|
2020-01-30 09:06:16 +00:00
|
|
|
filters: this.filters,
|
2020-02-07 07:48:12 +00:00
|
|
|
filterMatchModes: filterMatchModes
|
2020-01-30 09:06:16 +00:00
|
|
|
};
|
2020-09-23 17:55:00 +00:00
|
|
|
},
|
2020-11-25 10:33:51 +00:00
|
|
|
hasFilters() {
|
|
|
|
return this.filters && Object.keys(this.filters).length > 0 && this.filters.constructor === Object;
|
|
|
|
},
|
|
|
|
hasGlobalFilter() {
|
|
|
|
return this.filters && Object.prototype.hasOwnProperty.call(this.filters, 'global');
|
2020-12-09 13:38:24 +00:00
|
|
|
},
|
|
|
|
getChildren() {
|
|
|
|
return this.$slots.default ? this.$slots.default() : null;
|
2021-02-06 09:26:12 +00:00
|
|
|
},
|
2021-02-06 22:42:14 +00:00
|
|
|
onFilterChange(filters) {
|
|
|
|
this.d_filters = filters;
|
|
|
|
},
|
|
|
|
onFilterApply() {
|
|
|
|
this.$emit('update:filters', this.d_filters);
|
|
|
|
},
|
|
|
|
cloneFilters() {
|
|
|
|
let cloned = {};
|
|
|
|
if (this.filters) {
|
2021-02-06 23:47:55 +00:00
|
|
|
cloned = JSON.parse(JSON.stringify(this.filters));
|
2021-02-06 22:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cloned;
|
2020-11-25 10:33:51 +00:00
|
|
|
}
|
2019-06-28 14:40:32 +00:00
|
|
|
},
|
2019-06-29 11:29:19 +00:00
|
|
|
computed: {
|
2019-07-03 10:07:57 +00:00
|
|
|
containerClass() {
|
|
|
|
return [
|
|
|
|
'p-datatable p-component', {
|
2019-07-10 14:20:12 +00:00
|
|
|
'p-datatable-hoverable-rows': (this.rowHover || this.selectionMode),
|
2019-08-07 13:50:07 +00:00
|
|
|
'p-datatable-auto-layout': this.autoLayout,
|
2019-10-01 13:00:26 +00:00
|
|
|
'p-datatable-resizable': this.resizableColumns,
|
2019-11-18 13:56:33 +00:00
|
|
|
'p-datatable-resizable-fit': this.resizableColumns && this.columnResizeMode === 'fit',
|
2019-11-19 11:54:24 +00:00
|
|
|
'p-datatable-scrollable': this.scrollable,
|
2020-05-27 12:12:12 +00:00
|
|
|
'p-datatable-virtual-scrollable': this.virtualScroll,
|
|
|
|
'p-datatable-flex-scrollable': (this.scrollable && this.scrollHeight === 'flex')
|
2019-07-03 10:07:57 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
},
|
2019-07-02 09:02:55 +00:00
|
|
|
columns() {
|
2020-09-23 19:48:53 +00:00
|
|
|
let cols = [];
|
2020-12-09 13:38:24 +00:00
|
|
|
let children = this.getChildren();
|
|
|
|
|
|
|
|
if (!children) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-27 18:29:11 +00:00
|
|
|
|
2020-09-23 19:48:53 +00:00
|
|
|
children.forEach(child => {
|
|
|
|
if (child.dynamicChildren)
|
|
|
|
cols = [...cols, ...child.children];
|
|
|
|
else if (child.type.name === 'column')
|
|
|
|
cols.push(child);
|
|
|
|
});
|
2020-09-23 17:55:00 +00:00
|
|
|
|
|
|
|
if (this.reorderableColumns && this.d_columnOrder) {
|
|
|
|
let orderedColumns = [];
|
|
|
|
for (let columnKey of this.d_columnOrder) {
|
2020-09-23 19:48:53 +00:00
|
|
|
let column = this.findColumnByKey(cols, columnKey);
|
2020-09-23 17:55:00 +00:00
|
|
|
if (column) {
|
|
|
|
orderedColumns.push(column);
|
2019-10-17 11:50:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-23 17:55:00 +00:00
|
|
|
|
2020-09-24 08:05:14 +00:00
|
|
|
return [...orderedColumns, ...cols.filter((item) => orderedColumns.indexOf(item) < 0)];
|
2019-07-02 09:02:55 +00:00
|
|
|
}
|
2020-09-27 18:29:11 +00:00
|
|
|
|
2020-09-23 19:48:53 +00:00
|
|
|
return cols;
|
2019-07-02 09:02:55 +00:00
|
|
|
},
|
2019-11-19 07:51:23 +00:00
|
|
|
frozenColumns() {
|
|
|
|
let frozenColumns = [];
|
|
|
|
|
|
|
|
for(let col of this.columns) {
|
2021-02-02 13:21:10 +00:00
|
|
|
if(this.columnProp(col, 'frozen')) {
|
2019-11-19 07:51:23 +00:00
|
|
|
frozenColumns = frozenColumns||[];
|
|
|
|
frozenColumns.push(col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frozenColumns;
|
|
|
|
},
|
|
|
|
scrollableColumns() {
|
|
|
|
let scrollableColumns = [];
|
|
|
|
|
|
|
|
for(let col of this.columns) {
|
2021-02-02 13:21:10 +00:00
|
|
|
if(!this.columnProp(col, 'frozen')) {
|
2019-11-19 07:51:23 +00:00
|
|
|
scrollableColumns = scrollableColumns||[];
|
|
|
|
scrollableColumns.push(col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return scrollableColumns;
|
|
|
|
},
|
|
|
|
hasFrozenColumns() {
|
|
|
|
return this.frozenColumns.length > 0;
|
|
|
|
},
|
2019-10-16 03:50:25 +00:00
|
|
|
headerColumnGroup() {
|
2020-12-09 13:38:24 +00:00
|
|
|
const children = this.getChildren();
|
|
|
|
if (children) {
|
|
|
|
for (let child of children) {
|
2021-02-02 13:21:10 +00:00
|
|
|
if (child.type.name === 'columngroup' && this.columnProp(child, 'type') === 'header') {
|
2020-12-09 13:38:24 +00:00
|
|
|
return child;
|
|
|
|
}
|
2019-10-16 03:50:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-11-19 07:51:23 +00:00
|
|
|
frozenHeaderColumnGroup() {
|
2020-12-09 13:38:24 +00:00
|
|
|
const children = this.getChildren();
|
|
|
|
if (children) {
|
|
|
|
for (let child of children) {
|
2021-02-02 13:21:10 +00:00
|
|
|
if (child.type.name === 'columngroup' && this.columnProp(child, 'type') === 'frozenheader') {
|
2020-12-09 13:38:24 +00:00
|
|
|
return child;
|
|
|
|
}
|
2019-11-19 07:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-10-16 03:50:25 +00:00
|
|
|
footerColumnGroup() {
|
2020-12-09 13:38:24 +00:00
|
|
|
const children = this.getChildren();
|
|
|
|
if (children) {
|
|
|
|
for (let child of children) {
|
2021-02-02 13:21:10 +00:00
|
|
|
if (child.type.name === 'columngroup' && this.columnProp(child, 'type') === 'footer') {
|
2020-12-09 13:38:24 +00:00
|
|
|
return child;
|
|
|
|
}
|
2019-10-16 03:50:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-11-19 07:51:23 +00:00
|
|
|
frozenFooterColumnGroup() {
|
2020-12-09 13:38:24 +00:00
|
|
|
const children = this.getChildren();
|
|
|
|
if (children) {
|
|
|
|
for (let child of children) {
|
2021-02-02 13:21:10 +00:00
|
|
|
if (child.type.name === 'columngroup' && this.columnProp(child, 'type') === 'frozenfooter') {
|
2020-12-09 13:38:24 +00:00
|
|
|
return child;
|
|
|
|
}
|
2019-11-19 07:51:23 +00:00
|
|
|
}
|
2020-12-09 13:38:24 +00:00
|
|
|
}
|
2019-11-19 07:51:23 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2019-07-02 14:12:19 +00:00
|
|
|
processedData() {
|
2019-07-10 18:09:22 +00:00
|
|
|
if (this.lazy) {
|
|
|
|
return this.value;
|
2019-06-29 11:29:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-07-10 18:09:22 +00:00
|
|
|
if (this.value && this.value.length) {
|
|
|
|
let data = this.value;
|
|
|
|
|
|
|
|
if (this.sorted) {
|
|
|
|
if(this.sortMode === 'single')
|
|
|
|
data = this.sortSingle(data);
|
|
|
|
else if(this.sortMode === 'multiple')
|
|
|
|
data = this.sortMultiple(data);
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:33:51 +00:00
|
|
|
if (this.hasFilters()) {
|
2019-07-10 18:09:22 +00:00
|
|
|
data = this.filter(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return null;
|
|
|
|
}
|
2019-06-29 11:29:19 +00:00
|
|
|
}
|
|
|
|
},
|
2019-07-02 14:12:19 +00:00
|
|
|
dataToRender() {
|
|
|
|
const data = this.processedData;
|
2019-11-18 14:06:16 +00:00
|
|
|
|
2019-11-18 11:52:17 +00:00
|
|
|
if (data && this.paginator) {
|
2019-07-02 14:12:19 +00:00
|
|
|
const first = this.lazy ? 0 : this.d_first;
|
|
|
|
return data.slice(first, first + this.d_rows);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
2019-06-29 11:29:19 +00:00
|
|
|
totalRecordsLength() {
|
2019-07-02 14:12:19 +00:00
|
|
|
if (this.lazy) {
|
2019-06-29 11:29:19 +00:00
|
|
|
return this.totalRecords;
|
2019-07-02 14:12:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-07-09 12:41:15 +00:00
|
|
|
const data = this.processedData;
|
2019-07-02 14:12:19 +00:00
|
|
|
return data ? data.length : 0;
|
|
|
|
}
|
2019-06-29 11:29:19 +00:00
|
|
|
},
|
|
|
|
empty() {
|
2019-07-10 18:09:22 +00:00
|
|
|
const data = this.processedData;
|
|
|
|
return (!data || data.length === 0);
|
2019-06-29 11:29:19 +00:00
|
|
|
},
|
|
|
|
paginatorTop() {
|
2019-06-29 12:27:35 +00:00
|
|
|
return this.paginator && (this.paginatorPosition !== 'bottom' || this.paginatorPosition === 'both');
|
2019-06-29 11:29:19 +00:00
|
|
|
},
|
|
|
|
paginatorBottom() {
|
2019-06-29 12:27:35 +00:00
|
|
|
return this.paginator && (this.paginatorPosition !== 'top' || this.paginatorPosition === 'both');
|
2019-07-02 10:15:50 +00:00
|
|
|
},
|
|
|
|
sorted() {
|
|
|
|
return this.d_sortField || (this.d_multiSortMeta && this.d_multiSortMeta.length > 0);
|
2019-07-02 10:46:06 +00:00
|
|
|
},
|
2019-07-02 14:29:30 +00:00
|
|
|
loadingIconClass() {
|
|
|
|
return ['p-datatable-loading-icon pi-spin', this.loadingIcon];
|
2019-07-09 12:41:15 +00:00
|
|
|
},
|
|
|
|
allRowsSelected() {
|
|
|
|
const val = this.processedData;
|
2019-07-09 13:15:42 +00:00
|
|
|
return (val && val.length > 0 && this.selection && this.selection.length > 0 && this.selection.length === val.length);
|
2019-06-29 11:47:14 +00:00
|
|
|
}
|
2019-06-29 11:29:19 +00:00
|
|
|
},
|
2019-06-28 14:40:32 +00:00
|
|
|
components: {
|
2019-07-09 11:36:24 +00:00
|
|
|
'DTPaginator': Paginator,
|
2019-11-18 13:56:33 +00:00
|
|
|
'DTScrollableView': ScrollableView,
|
2019-11-18 08:00:39 +00:00
|
|
|
'DTTableHeader': TableHeader,
|
2019-11-18 11:52:17 +00:00
|
|
|
'DTTableBody': TableBody,
|
|
|
|
'DTTableFooter': TableFooter,
|
2019-06-27 21:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.p-datatable {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable table {
|
|
|
|
border-collapse: collapse;
|
|
|
|
width: 100%;
|
|
|
|
table-layout: fixed;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable .p-sortable-column {
|
|
|
|
cursor: pointer;
|
2020-04-18 16:03:21 +00:00
|
|
|
user-select: none;
|
2019-06-27 21:17:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 09:34:12 +00:00
|
|
|
.p-datatable .p-sortable-column .p-column-title,
|
|
|
|
.p-datatable .p-sortable-column .p-sortable-column-icon,
|
|
|
|
.p-datatable .p-sortable-column .p-sortable-column-badge {
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable .p-sortable-column .p-sortable-column-badge {
|
2020-07-01 15:57:26 +00:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-04-28 09:34:12 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
.p-datatable-auto-layout > .p-datatable-wrapper {
|
|
|
|
overflow-x: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-auto-layout > .p-datatable-wrapper > table {
|
|
|
|
table-layout: auto;
|
|
|
|
}
|
|
|
|
|
2020-07-18 11:31:49 +00:00
|
|
|
.p-datatable-hoverable-rows .p-selectable-row {
|
2019-08-07 09:40:29 +00:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
/* Scrollable */
|
|
|
|
.p-datatable-scrollable-wrapper {
|
|
|
|
position: relative;
|
|
|
|
}
|
2020-04-24 15:13:48 +00:00
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
.p-datatable-scrollable-header,
|
|
|
|
.p-datatable-scrollable-footer {
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-scrollable-body {
|
|
|
|
overflow: auto;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-scrollable-body > table > .p-datatable-tbody > tr:first-child > td {
|
|
|
|
border-top: 0 none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-virtual-table {
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Frozen Columns */
|
|
|
|
.p-datatable-frozen-view .p-datatable-scrollable-body {
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-frozen-view > .p-datatable-scrollable-body > table > .p-datatable-tbody > tr > td:last-child {
|
|
|
|
border-right: 0 none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-unfrozen-view {
|
|
|
|
position: absolute;
|
2020-04-24 15:13:48 +00:00
|
|
|
top: 0;
|
2019-06-27 21:17:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 12:12:12 +00:00
|
|
|
/* Flex Scrollable */
|
|
|
|
.p-datatable-flex-scrollable {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex: 1;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-flex-scrollable .p-datatable-scrollable-wrapper,
|
|
|
|
.p-datatable-flex-scrollable .p-datatable-scrollable-view {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
flex: 1;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-flex-scrollable .p-datatable-scrollable-body {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
/* Resizable */
|
|
|
|
.p-datatable-resizable > .p-datatable-wrapper {
|
|
|
|
overflow-x: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-resizable .p-datatable-thead > tr > th,
|
|
|
|
.p-datatable-resizable .p-datatable-tfoot > tr > td,
|
|
|
|
.p-datatable-resizable .p-datatable-tbody > tr > td {
|
|
|
|
overflow: hidden;
|
2020-08-04 11:38:58 +00:00
|
|
|
white-space: nowrap;
|
2019-06-27 21:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-resizable .p-resizable-column {
|
|
|
|
background-clip: padding-box;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable-resizable-fit .p-resizable-column:last-child .p-column-resizer {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-datatable .p-column-resizer {
|
|
|
|
display: block;
|
|
|
|
position: absolute !important;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
margin: 0;
|
2020-05-14 08:51:13 +00:00
|
|
|
width: .5rem;
|
2019-06-27 21:17:21 +00:00
|
|
|
height: 100%;
|
|
|
|
padding: 0px;
|
|
|
|
cursor:col-resize;
|
|
|
|
border: 1px solid transparent;
|
|
|
|
}
|
|
|
|
|
2021-02-06 12:21:39 +00:00
|
|
|
.p-column-header-content {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
.p-datatable .p-column-resizer-helper {
|
|
|
|
width: 1px;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10;
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:37:46 +00:00
|
|
|
.p-datatable .p-row-editor-init,
|
|
|
|
.p-datatable .p-row-editor-save,
|
|
|
|
.p-datatable .p-row-editor-cancel {
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-07-01 08:59:21 +00:00
|
|
|
overflow: hidden;
|
|
|
|
position: relative;
|
2020-06-30 09:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Expand */
|
|
|
|
.p-datatable .p-row-toggler {
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-07-01 08:59:21 +00:00
|
|
|
overflow: hidden;
|
|
|
|
position: relative;
|
2020-06-30 09:37:46 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 21:17:21 +00:00
|
|
|
/* Reorder */
|
|
|
|
.p-datatable-reorder-indicator-up,
|
|
|
|
.p-datatable-reorder-indicator-down {
|
|
|
|
position: absolute;
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Loader */
|
2020-04-30 22:16:22 +00:00
|
|
|
.p-datatable .p-datatable-loading-overlay {
|
2019-06-27 21:17:21 +00:00
|
|
|
position: absolute;
|
2020-04-24 15:13:48 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-08-04 12:11:16 +00:00
|
|
|
z-index: 2;
|
2019-06-27 21:17:21 +00:00
|
|
|
}
|
2021-02-06 09:26:12 +00:00
|
|
|
|
|
|
|
/* Filter */
|
|
|
|
.p-column-filter-row {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-menu {
|
|
|
|
display: inline-flex;
|
2021-02-06 12:21:39 +00:00
|
|
|
margin-left: auto;
|
2021-02-06 09:26:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 12:21:39 +00:00
|
|
|
.p-column-filter-row .p-column-filter-element {
|
2021-02-06 09:26:12 +00:00
|
|
|
flex: 1 1 auto;
|
|
|
|
width: 1%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-menu-button,
|
|
|
|
.p-column-filter-clear-button {
|
|
|
|
display: inline-flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
cursor: pointer;
|
|
|
|
text-decoration: none;
|
|
|
|
overflow: hidden;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-overlay {
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-row-items {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
list-style: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-row-item {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-add-button,
|
|
|
|
.p-column-filter-remove-button {
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-add-button .p-button-label,
|
|
|
|
.p-column-filter-remove-button .p-button-label {
|
|
|
|
flex-grow: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-buttonbar {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-column-filter-buttonbar .p-button {
|
|
|
|
width: auto;
|
|
|
|
}
|
2019-06-27 21:17:21 +00:00
|
|
|
</style>
|