2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-06-02 06:52:13 +00:00
|
|
|
<div :class="cx('root')" data-scrollselectors=".p-datatable-wrapper" v-bind="ptm('root')" data-pc-name="datatable">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot></slot>
|
2023-06-02 06:52:13 +00:00
|
|
|
<div v-if="loading" :class="cx('loadingOverlay')" v-bind="ptm('loadingOverlay')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<slot v-if="$slots.loading" name="loading"></slot>
|
2023-04-18 07:35:20 +00:00
|
|
|
<template v-else>
|
2023-06-02 06:52:13 +00:00
|
|
|
<component v-if="$slots.loadingicon" :is="$slots.loadingicon" :class="cx('loadingIcon')" />
|
|
|
|
<i v-else-if="loadingIcon" :class="[cx('loadingIcon'), 'pi-spin', loadingIcon]" v-bind="ptm('loadingIcon')" />
|
|
|
|
<SpinnerIcon v-else spin :class="cx('loadingIcon')" v-bind="ptm('loadingIcon')" />
|
2023-04-18 07:35:20 +00:00
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-06-02 06:52:13 +00:00
|
|
|
<div v-if="$slots.header" :class="cx('header')" v-bind="ptm('header')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="header"></slot>
|
|
|
|
</div>
|
2022-09-14 11:26:01 +00:00
|
|
|
<DTPaginator
|
|
|
|
v-if="paginatorTop"
|
|
|
|
:rows="d_rows"
|
|
|
|
:first="d_first"
|
|
|
|
:totalRecords="totalRecordsLength"
|
|
|
|
:pageLinkSize="pageLinkSize"
|
|
|
|
:template="paginatorTemplate"
|
|
|
|
:rowsPerPageOptions="rowsPerPageOptions"
|
|
|
|
:currentPageReportTemplate="currentPageReportTemplate"
|
2023-06-02 06:52:13 +00:00
|
|
|
:class="cx('paginator')"
|
2022-09-14 11:26:01 +00:00
|
|
|
@page="onPage($event)"
|
|
|
|
:alwaysShow="alwaysShowPaginator"
|
2023-06-05 08:10:25 +00:00
|
|
|
:unstyled="unstyled"
|
2023-05-08 14:08:06 +00:00
|
|
|
:pt="ptm('paginator')"
|
2023-06-02 06:52:13 +00:00
|
|
|
data-pc-section="paginator"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
|
|
|
<template v-if="$slots.paginatorstart" #start>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="paginatorstart"></slot>
|
|
|
|
</template>
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-if="$slots.paginatorend" #end>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="paginatorend"></slot>
|
|
|
|
</template>
|
2023-04-14 14:58:51 +00:00
|
|
|
<template v-if="$slots.paginatorfirstpagelinkicon" #firstpagelinkicon>
|
|
|
|
<slot name="paginatorfirstpagelinkicon"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatorprevpagelinkicon" #prevpagelinkicon>
|
|
|
|
<slot name="paginatorprevpagelinkicon"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatornextpagelinkicon" #nextpagelinkicon>
|
|
|
|
<slot name="paginatornextpagelinkicon"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatorlastpagelinkicon" #lastpagelinkicon>
|
|
|
|
<slot name="paginatorlastpagelinkicon"></slot>
|
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</DTPaginator>
|
2023-06-05 11:18:11 +00:00
|
|
|
<div :class="cx('wrapper')" :style="[sx('wrapper'), { maxHeight: virtualScrollerDisabled ? scrollHeight : '' }]" v-bind="ptm('wrapper')">
|
2023-02-28 10:33:00 +00:00
|
|
|
<DTVirtualScroller
|
|
|
|
ref="virtualScroller"
|
2023-05-26 06:25:56 +00:00
|
|
|
v-bind="virtualScrollerOptions"
|
2023-02-28 10:33:00 +00:00
|
|
|
:items="processedData"
|
|
|
|
:columns="columns"
|
2023-03-27 09:35:52 +00:00
|
|
|
:style="scrollHeight !== 'flex' ? { height: scrollHeight } : undefined"
|
2023-02-28 10:33:00 +00:00
|
|
|
:scrollHeight="scrollHeight !== 'flex' ? undefined : '100%'"
|
|
|
|
:disabled="virtualScrollerDisabled"
|
|
|
|
loaderDisabled
|
|
|
|
inline
|
|
|
|
autoSize
|
|
|
|
:showSpacer="false"
|
2023-05-26 06:25:56 +00:00
|
|
|
:pt="ptm('virtualScroller')"
|
2023-02-28 10:33:00 +00:00
|
|
|
>
|
2022-09-06 12:03:37 +00:00
|
|
|
<template #content="slotProps">
|
2023-06-02 06:52:13 +00:00
|
|
|
<table ref="table" role="table" :class="[cx('table'), tableClass]" :style="[tableStyle, slotProps.spacerStyle]" v-bind="{ ...tableProps, ...ptm('table') }">
|
2022-09-14 11:26:01 +00:00
|
|
|
<DTTableHeader
|
|
|
|
:columnGroup="headerColumnGroup"
|
|
|
|
:columns="slotProps.columns"
|
|
|
|
:rowGroupMode="rowGroupMode"
|
|
|
|
:groupRowsBy="groupRowsBy"
|
|
|
|
:groupRowSortField="groupRowSortField"
|
|
|
|
:reorderableColumns="reorderableColumns"
|
|
|
|
:resizableColumns="resizableColumns"
|
|
|
|
:allRowsSelected="allRowsSelected"
|
|
|
|
:empty="empty"
|
|
|
|
:sortMode="sortMode"
|
|
|
|
:sortField="d_sortField"
|
|
|
|
:sortOrder="d_sortOrder"
|
|
|
|
:multiSortMeta="d_multiSortMeta"
|
|
|
|
:filters="d_filters"
|
|
|
|
:filtersStore="filters"
|
|
|
|
:filterDisplay="filterDisplay"
|
2022-12-08 11:04:25 +00:00
|
|
|
:filterInputProps="filterInputProps"
|
2023-04-13 14:42:33 +00:00
|
|
|
:headerCheckboxIconTemplate="$slots.headercheckboxicon"
|
2022-09-14 11:26:01 +00:00
|
|
|
@column-click="onColumnHeaderClick($event)"
|
|
|
|
@column-mousedown="onColumnHeaderMouseDown($event)"
|
|
|
|
@filter-change="onFilterChange"
|
|
|
|
@filter-apply="onFilterApply"
|
|
|
|
@column-dragstart="onColumnHeaderDragStart($event)"
|
|
|
|
@column-dragover="onColumnHeaderDragOver($event)"
|
|
|
|
@column-dragleave="onColumnHeaderDragLeave($event)"
|
|
|
|
@column-drop="onColumnHeaderDrop($event)"
|
|
|
|
@column-resizestart="onColumnResizeStart($event)"
|
|
|
|
@checkbox-change="toggleRowsWithCheckbox($event)"
|
2023-06-05 08:55:38 +00:00
|
|
|
:unstyled="unstyled"
|
2023-05-08 14:08:06 +00:00
|
|
|
:pt="pt"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
|
|
|
<DTTableBody
|
|
|
|
v-if="frozenValue"
|
|
|
|
ref="frozenBodyRef"
|
|
|
|
:value="frozenValue"
|
|
|
|
:frozenRow="true"
|
|
|
|
:columns="slotProps.columns"
|
2023-03-27 08:37:20 +00:00
|
|
|
:first="d_first"
|
2022-09-14 11:26:01 +00:00
|
|
|
:dataKey="dataKey"
|
|
|
|
:selection="selection"
|
|
|
|
:selectionKeys="d_selectionKeys"
|
|
|
|
:selectionMode="selectionMode"
|
|
|
|
:contextMenu="contextMenu"
|
|
|
|
:contextMenuSelection="contextMenuSelection"
|
|
|
|
:rowGroupMode="rowGroupMode"
|
|
|
|
:groupRowsBy="groupRowsBy"
|
|
|
|
:expandableRowGroups="expandableRowGroups"
|
|
|
|
:rowClass="rowClass"
|
|
|
|
:rowStyle="rowStyle"
|
|
|
|
:editMode="editMode"
|
|
|
|
:compareSelectionBy="compareSelectionBy"
|
|
|
|
:scrollable="scrollable"
|
|
|
|
:expandedRowIcon="expandedRowIcon"
|
|
|
|
:collapsedRowIcon="collapsedRowIcon"
|
|
|
|
:expandedRows="expandedRows"
|
|
|
|
:expandedRowKeys="d_expandedRowKeys"
|
|
|
|
:expandedRowGroups="expandedRowGroups"
|
|
|
|
:editingRows="editingRows"
|
|
|
|
:editingRowKeys="d_editingRowKeys"
|
|
|
|
:templates="$slots"
|
|
|
|
:responsiveLayout="responsiveLayout"
|
2022-12-08 11:04:25 +00:00
|
|
|
:isVirtualScrollerDisabled="true"
|
2022-09-14 11:26:01 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup"
|
|
|
|
@row-click="onRowClick($event)"
|
|
|
|
@row-dblclick="onRowDblClick($event)"
|
|
|
|
@row-rightclick="onRowRightClick($event)"
|
|
|
|
@row-touchend="onRowTouchEnd"
|
|
|
|
@row-keydown="onRowKeyDown"
|
|
|
|
@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)"
|
|
|
|
:editingMeta="d_editingMeta"
|
|
|
|
@editing-meta-change="onEditingMetaChange"
|
2023-06-05 08:55:38 +00:00
|
|
|
:unstyled="unstyled"
|
|
|
|
:pt="pt"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
|
|
|
<DTTableBody
|
|
|
|
ref="bodyRef"
|
|
|
|
:value="dataToRender(slotProps.rows)"
|
|
|
|
:class="slotProps.styleClass"
|
|
|
|
:columns="slotProps.columns"
|
|
|
|
:empty="empty"
|
2023-03-27 08:37:20 +00:00
|
|
|
:first="d_first"
|
2022-09-14 11:26:01 +00:00
|
|
|
:dataKey="dataKey"
|
|
|
|
:selection="selection"
|
|
|
|
:selectionKeys="d_selectionKeys"
|
|
|
|
:selectionMode="selectionMode"
|
|
|
|
:contextMenu="contextMenu"
|
|
|
|
:contextMenuSelection="contextMenuSelection"
|
|
|
|
:rowGroupMode="rowGroupMode"
|
|
|
|
:groupRowsBy="groupRowsBy"
|
|
|
|
:expandableRowGroups="expandableRowGroups"
|
|
|
|
:rowClass="rowClass"
|
|
|
|
:rowStyle="rowStyle"
|
|
|
|
:editMode="editMode"
|
|
|
|
:compareSelectionBy="compareSelectionBy"
|
|
|
|
:scrollable="scrollable"
|
|
|
|
:expandedRowIcon="expandedRowIcon"
|
|
|
|
:collapsedRowIcon="collapsedRowIcon"
|
|
|
|
:expandedRows="expandedRows"
|
|
|
|
:expandedRowKeys="d_expandedRowKeys"
|
|
|
|
:expandedRowGroups="expandedRowGroups"
|
|
|
|
:editingRows="editingRows"
|
|
|
|
:editingRowKeys="d_editingRowKeys"
|
|
|
|
:templates="$slots"
|
|
|
|
:responsiveLayout="responsiveLayout"
|
2022-12-08 11:04:25 +00:00
|
|
|
:virtualScrollerContentProps="slotProps"
|
|
|
|
:isVirtualScrollerDisabled="virtualScrollerDisabled"
|
2022-09-14 11:26:01 +00:00
|
|
|
@rowgroup-toggle="toggleRowGroup"
|
|
|
|
@row-click="onRowClick($event)"
|
|
|
|
@row-dblclick="onRowDblClick($event)"
|
|
|
|
@row-rightclick="onRowRightClick($event)"
|
|
|
|
@row-touchend="onRowTouchEnd"
|
2022-12-08 11:04:25 +00:00
|
|
|
@row-keydown="onRowKeyDown($event, slotProps)"
|
2022-09-14 11:26:01 +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)"
|
|
|
|
:editingMeta="d_editingMeta"
|
|
|
|
@editing-meta-change="onEditingMetaChange"
|
2023-06-05 08:55:38 +00:00
|
|
|
:unstyled="unstyled"
|
2023-05-08 14:08:06 +00:00
|
|
|
:pt="pt"
|
2022-09-14 11:26:01 +00:00
|
|
|
/>
|
2023-05-08 14:08:06 +00:00
|
|
|
<tbody
|
|
|
|
v-if="hasSpacerStyle(slotProps.spacerStyle)"
|
2023-06-02 06:52:13 +00:00
|
|
|
:class="cx('virtualScrollerSpacer')"
|
2023-05-08 14:08:06 +00:00
|
|
|
:style="{ height: `calc(${slotProps.spacerStyle.height} - ${slotProps.rows.length * slotProps.itemSize}px)` }"
|
|
|
|
v-bind="ptm('virtualScrollerSpacer')"
|
|
|
|
></tbody>
|
|
|
|
<DTTableFooter :columnGroup="footerColumnGroup" :columns="slotProps.columns" :pt="pt" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</table>
|
|
|
|
</template>
|
|
|
|
</DTVirtualScroller>
|
|
|
|
</div>
|
2023-06-02 06:52:13 +00:00
|
|
|
<div v-if="$slots.footer" :class="cx('footer')" v-bind="ptm('footer')">
|
2023-01-26 13:22:54 +00:00
|
|
|
<slot name="footer"></slot>
|
|
|
|
</div>
|
2022-09-14 11:26:01 +00:00
|
|
|
<DTPaginator
|
|
|
|
v-if="paginatorBottom"
|
|
|
|
:rows="d_rows"
|
|
|
|
:first="d_first"
|
|
|
|
:totalRecords="totalRecordsLength"
|
|
|
|
:pageLinkSize="pageLinkSize"
|
|
|
|
:template="paginatorTemplate"
|
|
|
|
:rowsPerPageOptions="rowsPerPageOptions"
|
|
|
|
:currentPageReportTemplate="currentPageReportTemplate"
|
2023-06-02 06:52:13 +00:00
|
|
|
:class="cx('paginator')"
|
2022-09-14 11:26:01 +00:00
|
|
|
@page="onPage($event)"
|
|
|
|
:alwaysShow="alwaysShowPaginator"
|
2023-06-05 08:10:25 +00:00
|
|
|
:unstyled="unstyled"
|
2023-05-09 14:57:31 +00:00
|
|
|
:pt="ptm('paginator')"
|
2023-06-02 06:52:13 +00:00
|
|
|
data-pc-section="paginator"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
|
|
|
<template v-if="$slots.paginatorstart" #start>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="paginatorstart"></slot>
|
|
|
|
</template>
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-if="$slots.paginatorend" #end>
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot name="paginatorend"></slot>
|
|
|
|
</template>
|
2023-04-14 14:58:51 +00:00
|
|
|
<template v-if="$slots.paginatorfirstpagelinkicon" #firstpagelinkicon>
|
|
|
|
<slot name="paginatorfirstpagelinkicon"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatorprevpagelinkicon" #prevpagelinkicon>
|
|
|
|
<slot name="paginatorprevpagelinkicon"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatornextpagelinkicon" #nextpagelinkicon>
|
|
|
|
<slot name="paginatornextpagelinkicon"></slot>
|
|
|
|
</template>
|
|
|
|
<template v-if="$slots.paginatorlastpagelinkicon" #lastpagelinkicon>
|
|
|
|
<slot name="paginatorlastpagelinkicon"></slot>
|
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</DTPaginator>
|
2023-06-02 06:52:13 +00:00
|
|
|
<div ref="resizeHelper" :class="cx('resizeHelper')" style="display: none" v-bind="ptm('resizeHelper')"></div>
|
|
|
|
<span v-if="reorderableColumns" ref="reorderIndicatorUp" :class="cx('reorderIndicatorUp')" style="position: absolute; display: none" v-bind="ptm('reorderIndicatorUp')">
|
2023-04-13 14:42:33 +00:00
|
|
|
<component :is="$slots.reorderindicatorupicon || 'ArrowDownIcon'" />
|
|
|
|
</span>
|
2023-06-02 06:52:13 +00:00
|
|
|
<span v-if="reorderableColumns" ref="reorderIndicatorDown" :class="cx('reorderIndicatorDown')" style="position: absolute; display: none" v-bind="ptm('reorderIndicatorDown')">
|
2023-04-13 14:42:33 +00:00
|
|
|
<component :is="$slots.reorderindicatordownicon || 'ArrowUpIcon'" />
|
|
|
|
</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-09-14 11:26:01 +00:00
|
|
|
import { FilterMatchMode, FilterOperator, FilterService } from 'primevue/api';
|
2023-04-18 12:53:43 +00:00
|
|
|
import ArrowDownIcon from 'primevue/icons/arrowdown';
|
|
|
|
import ArrowUpIcon from 'primevue/icons/arrowup';
|
|
|
|
import SpinnerIcon from 'primevue/icons/spinner';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Paginator from 'primevue/paginator';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
import VirtualScroller from 'primevue/virtualscroller';
|
2023-06-02 06:52:13 +00:00
|
|
|
import BaseDataTable from './BaseDataTable.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
import TableBody from './TableBody.vue';
|
|
|
|
import TableFooter from './TableFooter.vue';
|
2022-12-08 11:04:25 +00:00
|
|
|
import TableHeader from './TableHeader.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DataTable',
|
2023-06-02 06:52:13 +00:00
|
|
|
extends: BaseDataTable,
|
2022-09-14 11:26:01 +00:00
|
|
|
emits: [
|
|
|
|
'value-change',
|
|
|
|
'update:first',
|
|
|
|
'update:rows',
|
|
|
|
'page',
|
|
|
|
'update:sortField',
|
|
|
|
'update:sortOrder',
|
|
|
|
'update:multiSortMeta',
|
|
|
|
'sort',
|
|
|
|
'filter',
|
|
|
|
'row-click',
|
|
|
|
'row-dblclick',
|
|
|
|
'update:selection',
|
|
|
|
'row-select',
|
|
|
|
'row-unselect',
|
|
|
|
'update:contextMenuSelection',
|
|
|
|
'row-contextmenu',
|
|
|
|
'row-unselect-all',
|
|
|
|
'row-select-all',
|
|
|
|
'select-all-change',
|
|
|
|
'column-resize-end',
|
|
|
|
'column-reorder',
|
|
|
|
'row-reorder',
|
|
|
|
'update:expandedRows',
|
|
|
|
'row-collapse',
|
|
|
|
'row-expand',
|
|
|
|
'update:expandedRowGroups',
|
|
|
|
'rowgroup-collapse',
|
|
|
|
'rowgroup-expand',
|
|
|
|
'update:filters',
|
|
|
|
'state-restore',
|
|
|
|
'state-save',
|
|
|
|
'cell-edit-init',
|
|
|
|
'cell-edit-complete',
|
|
|
|
'cell-edit-cancel',
|
|
|
|
'update:editingRows',
|
|
|
|
'row-edit-init',
|
|
|
|
'row-edit-save',
|
|
|
|
'row-edit-cancel'
|
|
|
|
],
|
2022-09-06 12:03:37 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
d_first: this.first,
|
|
|
|
d_rows: this.rows,
|
|
|
|
d_sortField: this.sortField,
|
|
|
|
d_sortOrder: this.sortOrder,
|
|
|
|
d_multiSortMeta: this.multiSortMeta ? [...this.multiSortMeta] : [],
|
|
|
|
d_groupRowsSortMeta: null,
|
|
|
|
d_selectionKeys: null,
|
|
|
|
d_expandedRowKeys: null,
|
|
|
|
d_columnOrder: null,
|
|
|
|
d_editingRowKeys: null,
|
|
|
|
d_editingMeta: {},
|
|
|
|
d_filters: this.cloneFilters(this.filters)
|
|
|
|
};
|
|
|
|
},
|
|
|
|
rowTouched: false,
|
|
|
|
anchorRowIndex: null,
|
|
|
|
rangeRowIndex: null,
|
|
|
|
documentColumnResizeListener: null,
|
|
|
|
documentColumnResizeEndListener: null,
|
|
|
|
lastResizeHelperX: null,
|
|
|
|
resizeColumnElement: null,
|
|
|
|
columnResizing: false,
|
|
|
|
colReorderIconWidth: null,
|
|
|
|
colReorderIconHeight: null,
|
|
|
|
draggedColumn: null,
|
|
|
|
draggedRowIndex: null,
|
|
|
|
droppedRowIndex: null,
|
|
|
|
rowDragging: null,
|
|
|
|
columnWidthsState: null,
|
|
|
|
tableWidthState: null,
|
|
|
|
columnWidthsRestored: false,
|
|
|
|
watch: {
|
|
|
|
first(newValue) {
|
|
|
|
this.d_first = newValue;
|
|
|
|
},
|
|
|
|
rows(newValue) {
|
|
|
|
this.d_rows = newValue;
|
|
|
|
},
|
|
|
|
sortField(newValue) {
|
|
|
|
this.d_sortField = newValue;
|
|
|
|
},
|
|
|
|
sortOrder(newValue) {
|
|
|
|
this.d_sortOrder = newValue;
|
|
|
|
},
|
|
|
|
multiSortMeta(newValue) {
|
|
|
|
this.d_multiSortMeta = newValue;
|
|
|
|
},
|
|
|
|
selection: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newValue) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
this.updateSelectionKeys(newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
expandedRows(newValue) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
this.updateExpandedRowKeys(newValue);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
editingRows(newValue) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
this.updateEditingRowKeys(newValue);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
deep: true,
|
2022-09-14 11:26:01 +00:00
|
|
|
handler: function (newValue) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_filters = this.cloneFilters(newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
|
|
|
if (this.isStateful()) {
|
|
|
|
this.restoreState();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$el.setAttribute(this.attributeSelector, '');
|
|
|
|
|
2023-06-05 11:24:13 +00:00
|
|
|
if (this.responsiveLayout === 'stack' && !this.scrollable && !this.unstyled) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.createResponsiveStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isStateful() && this.resizableColumns) {
|
|
|
|
this.restoreColumnWidths();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.editMode === 'row' && this.dataKey && !this.d_editingRowKeys) {
|
|
|
|
this.updateEditingRowKeys(this.editingRows);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
this.unbindColumnResizeEvents();
|
|
|
|
this.destroyStyleElement();
|
|
|
|
this.destroyResponsiveStyle();
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
if (this.isStateful()) {
|
|
|
|
this.saveState();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.editMode === 'row' && this.dataKey && !this.d_editingRowKeys) {
|
|
|
|
this.updateEditingRowKeys(this.editingRows);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
columnProp(col, prop) {
|
|
|
|
return ObjectUtils.getVNodeProp(col, prop);
|
|
|
|
},
|
|
|
|
onPage(event) {
|
|
|
|
this.clearEditingMetaData();
|
|
|
|
|
|
|
|
this.d_first = event.first;
|
|
|
|
this.d_rows = event.rows;
|
|
|
|
|
|
|
|
let pageEvent = this.createLazyLoadEvent(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
pageEvent.pageCount = event.pageCount;
|
|
|
|
pageEvent.page = event.page;
|
|
|
|
|
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
this.$emit('update:rows', this.d_rows);
|
|
|
|
this.$emit('page', pageEvent);
|
|
|
|
this.$emit('value-change', this.processedData);
|
|
|
|
},
|
|
|
|
onColumnHeaderClick(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const column = e.column;
|
|
|
|
|
|
|
|
if (this.columnProp(column, 'sortable')) {
|
|
|
|
const targetNode = event.target;
|
|
|
|
const columnField = this.columnProp(column, 'sortField') || this.columnProp(column, 'field');
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (
|
2023-06-02 06:52:13 +00:00
|
|
|
DomHandler.getAttribute(targetNode, 'data-p-sortable-column') === true ||
|
2023-06-07 14:04:02 +00:00
|
|
|
DomHandler.getAttribute(targetNode, 'data-pc-section') === 'headertitle' ||
|
|
|
|
DomHandler.getAttribute(targetNode, 'data-pc-section') === 'headercontent' ||
|
|
|
|
DomHandler.getAttribute(targetNode, 'data-pc-section') === 'sorticon' ||
|
|
|
|
DomHandler.getAttribute(targetNode.parentElement, 'data-pc-section') === 'sorticon' ||
|
|
|
|
DomHandler.getAttribute(targetNode.parentElement.parentElement, 'data-pc-section') === 'sorticon'
|
2022-09-14 11:26:01 +00:00
|
|
|
) {
|
2022-09-06 12:03:37 +00:00
|
|
|
DomHandler.clearSelection();
|
|
|
|
|
|
|
|
if (this.sortMode === 'single') {
|
|
|
|
if (this.d_sortField === columnField) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.removableSort && this.d_sortOrder * -1 === this.defaultSortOrder) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_sortOrder = null;
|
|
|
|
this.d_sortField = null;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_sortOrder = this.d_sortOrder * -1;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_sortOrder = this.defaultSortOrder;
|
|
|
|
this.d_sortField = columnField;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('update:sortField', this.d_sortField);
|
|
|
|
this.$emit('update:sortOrder', this.d_sortOrder);
|
|
|
|
this.resetPage();
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.sortMode === 'multiple') {
|
2022-09-06 12:03:37 +00:00
|
|
|
let metaKey = event.metaKey || event.ctrlKey;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (!metaKey) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.d_multiSortMeta = this.d_multiSortMeta.filter((meta) => meta.field === columnField);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.addMultiSortField(columnField);
|
|
|
|
this.$emit('update:multiSortMeta', this.d_multiSortMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('sort', this.createLazyLoadEvent(event));
|
|
|
|
this.$emit('value-change', this.processedData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sortSingle(value) {
|
|
|
|
this.clearEditingMetaData();
|
|
|
|
|
|
|
|
if (this.groupRowsBy && this.groupRowsBy === this.sortField) {
|
|
|
|
this.d_multiSortMeta = [
|
2022-09-14 11:26:01 +00:00
|
|
|
{ field: this.sortField, order: this.sortOrder || this.defaultSortOrder },
|
|
|
|
{ field: this.d_sortField, order: this.d_sortOrder }
|
2022-09-06 12:03:37 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return this.sortMultiple(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = [...value];
|
|
|
|
|
|
|
|
data.sort((data1, data2) => {
|
|
|
|
let value1 = ObjectUtils.resolveFieldData(data1, this.d_sortField);
|
|
|
|
let value2 = ObjectUtils.resolveFieldData(data2, this.d_sortField);
|
|
|
|
|
|
|
|
let result = null;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
return this.d_sortOrder * result;
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
sortMultiple(value) {
|
|
|
|
this.clearEditingMetaData();
|
|
|
|
|
|
|
|
if (this.groupRowsBy && (this.d_groupRowsSortMeta || (this.d_multiSortMeta.length && this.groupRowsBy === this.d_multiSortMeta[0].field))) {
|
|
|
|
const firstSortMeta = this.d_multiSortMeta[0];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
!this.d_groupRowsSortMeta && (this.d_groupRowsSortMeta = firstSortMeta);
|
|
|
|
|
|
|
|
if (firstSortMeta.field !== this.d_groupRowsSortMeta.field) {
|
|
|
|
this.d_multiSortMeta = [this.d_groupRowsSortMeta, ...this.d_multiSortMeta];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = [...value];
|
|
|
|
|
|
|
|
data.sort((data1, data2) => {
|
|
|
|
return this.multisortField(data1, data2, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (typeof value1 === 'string' || value1 instanceof String) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (value1.localeCompare && value1 !== value2) {
|
|
|
|
return this.d_multiSortMeta[index].order * value1.localeCompare(value2, undefined, { numeric: true });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
result = value1 < value2 ? -1 : 1;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (value1 === value2) {
|
|
|
|
return this.d_multiSortMeta.length - 1 > index ? this.multisortField(data1, data2, index + 1) : 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.d_multiSortMeta[index].order * result;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
addMultiSortField(field) {
|
2022-09-14 11:26:01 +00:00
|
|
|
let index = this.d_multiSortMeta.findIndex((meta) => meta.field === field);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (index >= 0) {
|
2022-09-14 11:26:01 +00:00
|
|
|
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 });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.d_multiSortMeta = [...this.d_multiSortMeta];
|
|
|
|
},
|
|
|
|
filter(data) {
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEditingMetaData();
|
|
|
|
|
|
|
|
let globalFilterFieldsArray;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.filters['global']) {
|
2022-09-14 11:26:01 +00:00
|
|
|
globalFilterFieldsArray = this.globalFilterFields || this.columns.map((col) => this.columnProp(col, 'filterField') || this.columnProp(col, 'field'));
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let filteredValue = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
let localMatch = true;
|
|
|
|
let globalMatch = false;
|
|
|
|
let localFiltered = false;
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (filterMeta.operator) {
|
|
|
|
for (let filterConstraint of filterMeta.constraints) {
|
|
|
|
localMatch = this.executeLocalFilter(filterField, data[i], filterConstraint);
|
|
|
|
|
|
|
|
if ((filterMeta.operator === FilterOperator.OR && localMatch) || (filterMeta.operator === FilterOperator.AND && !localMatch)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
localMatch = this.executeLocalFilter(filterField, data[i], filterMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localMatch) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.filters['global'] && !globalMatch && globalFilterFieldsArray) {
|
2022-09-14 11:26:01 +00:00
|
|
|
for (let j = 0; j < globalFilterFieldsArray.length; j++) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let globalFilterField = globalFilterFieldsArray[j];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
globalMatch = FilterService.filters[this.filters['global'].matchMode || FilterMatchMode.CONTAINS](ObjectUtils.resolveFieldData(data[i], globalFilterField), this.filters['global'].value, this.filterLocale);
|
|
|
|
|
|
|
|
if (globalMatch) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let matches;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.filters['global']) {
|
2022-09-14 11:26:01 +00:00
|
|
|
matches = localFiltered ? localFiltered && localMatch && globalMatch : globalMatch;
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
matches = localFiltered && localMatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matches) {
|
|
|
|
filteredValue.push(data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filteredValue.length === this.value.length) {
|
|
|
|
filteredValue = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
let filterEvent = this.createLazyLoadEvent();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
filterEvent.filteredValue = filteredValue;
|
|
|
|
this.$emit('filter', filterEvent);
|
|
|
|
this.$emit('value-change', filteredValue);
|
|
|
|
|
|
|
|
return filteredValue;
|
|
|
|
},
|
|
|
|
executeLocalFilter(field, rowData, filterMeta) {
|
|
|
|
let filterValue = filterMeta.value;
|
|
|
|
let filterMatchMode = filterMeta.matchMode || FilterMatchMode.STARTS_WITH;
|
|
|
|
let dataFieldValue = ObjectUtils.resolveFieldData(rowData, field);
|
|
|
|
let filterConstraint = FilterService.filters[filterMatchMode];
|
|
|
|
|
|
|
|
return filterConstraint(dataFieldValue, filterValue, this.filterLocale);
|
|
|
|
},
|
|
|
|
onRowClick(e) {
|
|
|
|
const event = e.originalEvent;
|
2022-12-08 11:04:25 +00:00
|
|
|
const index = e.index;
|
|
|
|
const body = this.$refs.bodyRef && this.$refs.bodyRef.$el;
|
2023-06-02 06:52:13 +00:00
|
|
|
const focusedItem = DomHandler.findSingle(body, 'tr[data-p-selectable-row="true"][tabindex="0"]');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (DomHandler.isClickable(event.target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('row-click', e);
|
|
|
|
|
|
|
|
if (this.selectionMode) {
|
|
|
|
const rowData = e.data;
|
|
|
|
const rowIndex = this.d_first + e.index;
|
|
|
|
|
|
|
|
if (this.isMultipleSelectionMode() && event.shiftKey && this.anchorRowIndex != null) {
|
|
|
|
DomHandler.clearSelection();
|
|
|
|
this.rangeRowIndex = rowIndex;
|
|
|
|
this.selectRange(event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
const selected = this.isSelected(rowData);
|
|
|
|
const metaSelection = this.rowTouched ? false : this.metaKeySelection;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.anchorRowIndex = rowIndex;
|
|
|
|
this.rangeRowIndex = rowIndex;
|
|
|
|
|
|
|
|
if (metaSelection) {
|
|
|
|
let metaKey = event.metaKey || event.ctrlKey;
|
|
|
|
|
|
|
|
if (selected && metaKey) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.isSingleSelectionMode()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', null);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
const selectionIndex = this.findIndexInSelection(rowData);
|
2022-09-14 11:26:01 +00:00
|
|
|
const _selection = this.selection.filter((val, i) => i != selectionIndex);
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-unselect', { originalEvent: event, data: rowData, index: rowIndex, type: 'row' });
|
|
|
|
} else {
|
|
|
|
if (this.isSingleSelectionMode()) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', rowData);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.isMultipleSelectionMode()) {
|
|
|
|
let _selection = metaKey ? this.selection || [] : [];
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_selection = [..._selection, rowData];
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-select', { originalEvent: event, data: rowData, index: rowIndex, type: 'row' });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.selectionMode === 'single') {
|
|
|
|
if (selected) {
|
|
|
|
this.$emit('update:selection', null);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-unselect', { originalEvent: event, data: rowData, index: rowIndex, type: 'row' });
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', rowData);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-select', { originalEvent: event, data: rowData, index: rowIndex, type: 'row' });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.selectionMode === 'multiple') {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (selected) {
|
|
|
|
const selectionIndex = this.findIndexInSelection(rowData);
|
|
|
|
const _selection = this.selection.filter((val, i) => i != selectionIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', _selection);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-unselect', { originalEvent: event, data: rowData, index: rowIndex, type: 'row' });
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
const _selection = this.selection ? [...this.selection, rowData] : [rowData];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', _selection);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-select', { originalEvent: event, data: rowData, index: rowIndex, type: 'row' });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rowTouched = false;
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
if (focusedItem) {
|
|
|
|
focusedItem.tabIndex = '-1';
|
2023-06-02 06:52:13 +00:00
|
|
|
DomHandler.find(body, 'tr[data-p-selectable-row="true"]')[index].tabIndex = '0';
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDblClick(e) {
|
|
|
|
const event = e.originalEvent;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (DomHandler.isClickable(event.target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('row-dblclick', e);
|
|
|
|
},
|
|
|
|
onRowRightClick(event) {
|
2023-05-12 11:27:15 +00:00
|
|
|
if (this.contextMenu) {
|
2023-05-05 09:29:14 +00:00
|
|
|
DomHandler.clearSelection();
|
|
|
|
event.originalEvent.target.focus();
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.$emit('update:contextMenuSelection', event.data);
|
|
|
|
this.$emit('row-contextmenu', event);
|
|
|
|
},
|
|
|
|
onRowTouchEnd() {
|
|
|
|
this.rowTouched = true;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onRowKeyDown(e, slotProps) {
|
2022-09-06 12:03:37 +00:00
|
|
|
const event = e.originalEvent;
|
|
|
|
const rowData = e.data;
|
|
|
|
const rowIndex = e.index;
|
2022-12-08 11:04:25 +00:00
|
|
|
const metaKey = event.metaKey || event.ctrlKey;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (this.selectionMode) {
|
|
|
|
const row = event.target;
|
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
switch (event.code) {
|
|
|
|
case 'ArrowDown':
|
|
|
|
this.onArrowDownKey(event, row, rowIndex, slotProps);
|
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'ArrowUp':
|
|
|
|
this.onArrowUpKey(event, row, rowIndex, slotProps);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Home':
|
|
|
|
this.onHomeKey(event, row, rowIndex, slotProps);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'End':
|
|
|
|
this.onEndKey(event, row, rowIndex, slotProps);
|
|
|
|
break;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Enter':
|
|
|
|
this.onEnterKey(event, rowData, rowIndex);
|
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Space':
|
|
|
|
this.onSpaceKey(event, rowData, rowIndex, slotProps);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
case 'Tab':
|
|
|
|
this.onTabKey(event, rowIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
default:
|
2022-12-08 11:04:25 +00:00
|
|
|
if (event.code === 'KeyA' && metaKey) {
|
|
|
|
const data = this.dataToRender(slotProps.rows);
|
|
|
|
|
|
|
|
this.$emit('update:selection', data);
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
break;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onArrowDownKey(event, row, rowIndex, slotProps) {
|
|
|
|
const nextRow = this.findNextSelectableRow(row);
|
|
|
|
|
|
|
|
nextRow && this.focusRowChange(row, nextRow);
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
const data = this.dataToRender(slotProps.rows);
|
|
|
|
const nextRowIndex = rowIndex + 1 >= data.length ? data.length - 1 : rowIndex + 1;
|
|
|
|
|
|
|
|
this.onRowClick({ originalEvent: event, data: data[nextRowIndex], index: nextRowIndex });
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onArrowUpKey(event, row, rowIndex, slotProps) {
|
|
|
|
const prevRow = this.findPrevSelectableRow(row);
|
|
|
|
|
|
|
|
prevRow && this.focusRowChange(row, prevRow);
|
|
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
const data = this.dataToRender(slotProps.rows);
|
|
|
|
const prevRowIndex = rowIndex - 1 <= 0 ? 0 : rowIndex - 1;
|
|
|
|
|
|
|
|
this.onRowClick({ originalEvent: event, data: data[prevRowIndex], index: prevRowIndex });
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onHomeKey(event, row, rowIndex, slotProps) {
|
|
|
|
const firstRow = this.findFirstSelectableRow();
|
|
|
|
|
|
|
|
firstRow && this.focusRowChange(row, firstRow);
|
|
|
|
|
|
|
|
if (event.ctrlKey && event.shiftKey) {
|
|
|
|
const data = this.dataToRender(slotProps.rows);
|
|
|
|
|
|
|
|
this.$emit('update:selection', data.slice(0, rowIndex + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onEndKey(event, row, rowIndex, slotProps) {
|
|
|
|
const lastRow = this.findLastSelectableRow();
|
|
|
|
|
|
|
|
lastRow && this.focusRowChange(row, lastRow);
|
|
|
|
|
|
|
|
if (event.ctrlKey && event.shiftKey) {
|
|
|
|
const data = this.dataToRender(slotProps.rows);
|
|
|
|
|
|
|
|
this.$emit('update:selection', data.slice(rowIndex, data.length));
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onEnterKey(event, rowData, rowIndex) {
|
|
|
|
this.onRowClick({ originalEvent: event, data: rowData, index: rowIndex });
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
onSpaceKey(event, rowData, rowIndex, slotProps) {
|
|
|
|
this.onEnterKey(event, rowData, rowIndex);
|
|
|
|
|
|
|
|
if (event.shiftKey && this.selection !== null) {
|
|
|
|
const data = this.dataToRender(slotProps.rows);
|
|
|
|
let index;
|
|
|
|
|
|
|
|
if (this.selection.length > 0) {
|
|
|
|
let firstSelectedRowIndex, lastSelectedRowIndex;
|
|
|
|
|
|
|
|
firstSelectedRowIndex = ObjectUtils.findIndexInList(this.selection[0], data);
|
|
|
|
lastSelectedRowIndex = ObjectUtils.findIndexInList(this.selection[this.selection.length - 1], data);
|
|
|
|
|
|
|
|
index = rowIndex <= firstSelectedRowIndex ? lastSelectedRowIndex : firstSelectedRowIndex;
|
|
|
|
} else {
|
|
|
|
index = ObjectUtils.findIndexInList(this.selection, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
const _selection = index !== rowIndex ? data.slice(Math.min(index, rowIndex), Math.max(index, rowIndex) + 1) : rowData;
|
|
|
|
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onTabKey(event, rowIndex) {
|
|
|
|
const body = this.$refs.bodyRef && this.$refs.bodyRef.$el;
|
2023-06-02 06:52:13 +00:00
|
|
|
const rows = DomHandler.find(body, 'tr[data-p-selectable-row="true"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
if (event.code === 'Tab' && rows && rows.length > 0) {
|
2023-06-02 06:52:13 +00:00
|
|
|
const firstSelectedRow = DomHandler.findSingle(body, 'tr[data-p-highlight="true"]');
|
|
|
|
const focusedItem = DomHandler.findSingle(body, 'tr[data-p-selectable-row="true"][tabindex="0"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
if (firstSelectedRow) {
|
|
|
|
firstSelectedRow.tabIndex = '0';
|
2023-01-26 12:59:45 +00:00
|
|
|
focusedItem && focusedItem !== firstSelectedRow && (focusedItem.tabIndex = '-1');
|
2022-12-08 11:04:25 +00:00
|
|
|
} else {
|
|
|
|
rows[0].tabIndex = '0';
|
|
|
|
focusedItem !== rows[0] && (rows[rowIndex].tabIndex = '-1');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
findNextSelectableRow(row) {
|
|
|
|
let nextRow = row.nextElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextRow) {
|
2023-06-02 06:52:13 +00:00
|
|
|
if (DomHandler.getAttribute(nextRow, 'data-p-selectable-row') === true) return nextRow;
|
2022-09-14 11:26:01 +00:00
|
|
|
else return this.findNextSelectableRow(nextRow);
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
findPrevSelectableRow(row) {
|
|
|
|
let prevRow = row.previousElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevRow) {
|
2023-06-02 06:52:13 +00:00
|
|
|
if (DomHandler.getAttribute(prevRow, 'data-p-selectable-row') === true) return prevRow;
|
2022-09-14 11:26:01 +00:00
|
|
|
else return this.findPrevSelectableRow(prevRow);
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
findFirstSelectableRow() {
|
2023-06-02 06:52:13 +00:00
|
|
|
const firstRow = DomHandler.findSingle(this.$refs.table, 'tr[data-p-selectable-row="true"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
return firstRow;
|
|
|
|
},
|
|
|
|
findLastSelectableRow() {
|
2023-06-02 06:52:13 +00:00
|
|
|
const rows = DomHandler.find(this.$refs.table, 'tr[data-p-selectable-row="true"]');
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
return rows ? rows[rows.length - 1] : null;
|
|
|
|
},
|
|
|
|
focusRowChange(firstFocusableRow, currentFocusedRow) {
|
|
|
|
firstFocusableRow.tabIndex = '-1';
|
|
|
|
currentFocusedRow.tabIndex = '0';
|
|
|
|
DomHandler.focus(currentFocusedRow);
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
toggleRowWithRadio(event) {
|
|
|
|
const rowData = event.data;
|
|
|
|
|
|
|
|
if (this.isSelected(rowData)) {
|
|
|
|
this.$emit('update:selection', null);
|
|
|
|
this.$emit('row-unselect', { originalEvent: event.originalEvent, data: rowData, index: event.index, type: 'radiobutton' });
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', rowData);
|
|
|
|
this.$emit('row-select', { originalEvent: event.originalEvent, data: rowData, index: event.index, type: 'radiobutton' });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleRowWithCheckbox(event) {
|
|
|
|
const rowData = event.data;
|
|
|
|
|
|
|
|
if (this.isSelected(rowData)) {
|
|
|
|
const selectionIndex = this.findIndexInSelection(rowData);
|
|
|
|
const _selection = this.selection.filter((val, i) => i != selectionIndex);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
this.$emit('row-unselect', { originalEvent: event.originalEvent, data: rowData, index: event.index, type: 'checkbox' });
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let _selection = this.selection ? [...this.selection] : [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_selection = [..._selection, rowData];
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
this.$emit('row-select', { originalEvent: event.originalEvent, data: rowData, index: event.index, type: 'checkbox' });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleRowsWithCheckbox(event) {
|
|
|
|
if (this.selectAll !== null) {
|
|
|
|
this.$emit('select-all-change', event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
const { originalEvent, checked } = event;
|
|
|
|
let _selection = [];
|
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
_selection = this.frozenValue ? [...this.frozenValue, ...this.processedData] : this.processedData;
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-select-all', { originalEvent, data: _selection });
|
|
|
|
} else {
|
|
|
|
this.$emit('row-unselect-all', { originalEvent });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isSingleSelectionMode() {
|
|
|
|
return this.selectionMode === 'single';
|
|
|
|
},
|
|
|
|
isMultipleSelectionMode() {
|
|
|
|
return this.selectionMode === 'multiple';
|
|
|
|
},
|
|
|
|
isSelected(rowData) {
|
|
|
|
if (rowData && this.selection) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
return this.d_selectionKeys ? this.d_selectionKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined : false;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
if (this.selection instanceof Array) return this.findIndexInSelection(rowData) > -1;
|
|
|
|
else return this.equals(rowData, this.selection);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
findIndexInSelection(rowData) {
|
|
|
|
return this.findIndex(rowData, this.selection);
|
|
|
|
},
|
|
|
|
findIndex(rowData, collection) {
|
|
|
|
let index = -1;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (collection && collection.length) {
|
|
|
|
for (let i = 0; i < collection.length; i++) {
|
|
|
|
if (this.equals(rowData, collection[i])) {
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
updateSelectionKeys(selection) {
|
|
|
|
this.d_selectionKeys = {};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (Array.isArray(selection)) {
|
|
|
|
for (let data of selection) {
|
|
|
|
this.d_selectionKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_selectionKeys[String(ObjectUtils.resolveFieldData(selection, this.dataKey))] = 1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateExpandedRowKeys(expandedRows) {
|
|
|
|
if (expandedRows && expandedRows.length) {
|
|
|
|
this.d_expandedRowKeys = {};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let data of expandedRows) {
|
|
|
|
this.d_expandedRowKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_expandedRowKeys = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateEditingRowKeys(editingRows) {
|
|
|
|
if (editingRows && editingRows.length) {
|
|
|
|
this.d_editingRowKeys = {};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let data of editingRows) {
|
|
|
|
this.d_editingRowKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_editingRowKeys = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
equals(data1, data2) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.compareSelectionBy === 'equals' ? data1 === data2 : ObjectUtils.equals(data1, data2, this.dataKey);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
selectRange(event) {
|
|
|
|
let rangeStart, rangeEnd;
|
|
|
|
|
|
|
|
if (this.rangeRowIndex > this.anchorRowIndex) {
|
|
|
|
rangeStart = this.anchorRowIndex;
|
|
|
|
rangeEnd = this.rangeRowIndex;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.rangeRowIndex < this.anchorRowIndex) {
|
2022-09-06 12:03:37 +00:00
|
|
|
rangeStart = this.rangeRowIndex;
|
|
|
|
rangeEnd = this.anchorRowIndex;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
rangeStart = this.rangeRowIndex;
|
|
|
|
rangeEnd = this.rangeRowIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.lazy && this.paginator) {
|
|
|
|
rangeStart -= this.first;
|
|
|
|
rangeEnd -= this.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
const value = this.processedData;
|
|
|
|
let _selection = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
for (let i = rangeStart; i <= rangeEnd; i++) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let rangeRowData = value[i];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_selection.push(rangeRowData);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-select', { originalEvent: event, data: rangeRowData, type: 'row' });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('update:selection', _selection);
|
|
|
|
},
|
|
|
|
exportCSV(options, data) {
|
|
|
|
let csv = '\ufeff';
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
data = this.processedData;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
if (options && options.selectionOnly) data = this.selection || [];
|
|
|
|
else if (this.frozenValue) data = data ? [...this.frozenValue, ...data] : this.frozenValue;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//headers
|
|
|
|
let headerInitiated = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let i = 0; i < this.columns.length; i++) {
|
|
|
|
let column = this.columns[i];
|
|
|
|
|
|
|
|
if (this.columnProp(column, 'exportable') !== false && this.columnProp(column, 'field')) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (headerInitiated) csv += this.csvSeparator;
|
|
|
|
else headerInitiated = true;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
csv += '"' + (this.columnProp(column, 'exportHeader') || this.columnProp(column, 'header') || this.columnProp(column, 'field')) + '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//body
|
|
|
|
if (data) {
|
2022-09-14 11:26:01 +00:00
|
|
|
data.forEach((record) => {
|
2022-09-06 12:03:37 +00:00
|
|
|
csv += '\n';
|
|
|
|
let rowInitiated = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let i = 0; i < this.columns.length; i++) {
|
|
|
|
let column = this.columns[i];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.columnProp(column, 'exportable') !== false && this.columnProp(column, 'field')) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (rowInitiated) csv += this.csvSeparator;
|
|
|
|
else rowInitiated = true;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
let cellData = ObjectUtils.resolveFieldData(record, this.columnProp(column, 'field'));
|
|
|
|
|
|
|
|
if (cellData != null) {
|
|
|
|
if (this.exportFunction) {
|
|
|
|
cellData = this.exportFunction({
|
|
|
|
data: cellData,
|
|
|
|
field: this.columnProp(column, 'field')
|
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
} else cellData = String(cellData).replace(/"/g, '""');
|
|
|
|
} else cellData = '';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
csv += '"' + cellData + '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//footers
|
|
|
|
let footerInitiated = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let i = 0; i < this.columns.length; i++) {
|
|
|
|
let column = this.columns[i];
|
|
|
|
|
|
|
|
if (i === 0) csv += '\n';
|
|
|
|
|
2023-01-27 08:47:41 +00:00
|
|
|
if (this.columnProp(column, 'exportable') !== false && this.columnProp(column, 'exportFooter')) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (footerInitiated) csv += this.csvSeparator;
|
|
|
|
else footerInitiated = true;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
csv += '"' + (this.columnProp(column, 'exportFooter') || this.columnProp(column, 'footer') || this.columnProp(column, 'field')) + '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DomHandler.exportCSV(csv, this.exportFilename);
|
|
|
|
},
|
|
|
|
resetPage() {
|
|
|
|
this.d_first = 0;
|
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
},
|
|
|
|
onColumnResizeStart(event) {
|
|
|
|
let containerLeft = DomHandler.getOffset(this.$el).left;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.resizeColumnElement = event.target.parentElement;
|
|
|
|
this.columnResizing = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
this.lastResizeHelperX = event.pageX - containerLeft + this.$el.scrollLeft;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.bindColumnResizeEvents();
|
|
|
|
},
|
|
|
|
onColumnResize(event) {
|
|
|
|
let containerLeft = DomHandler.getOffset(this.$el).left;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-06-09 12:44:26 +00:00
|
|
|
this.$el.setAttribute('data-p-unselectable-text', 'true');
|
|
|
|
!this.isUnstyled && DomHandler.addClass(this.$el, 'p-unselectable-text');
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$refs.resizeHelper.style.height = this.$el.offsetHeight + 'px';
|
|
|
|
this.$refs.resizeHelper.style.top = 0 + 'px';
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$refs.resizeHelper.style.left = event.pageX - containerLeft + this.$el.scrollLeft + 'px';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.$refs.resizeHelper.style.display = 'block';
|
|
|
|
},
|
|
|
|
onColumnResizeEnd() {
|
|
|
|
let delta = this.$refs.resizeHelper.offsetLeft - this.lastResizeHelperX;
|
|
|
|
let columnWidth = this.resizeColumnElement.offsetWidth;
|
|
|
|
let newColumnWidth = columnWidth + delta;
|
2022-09-14 11:26:01 +00:00
|
|
|
let minWidth = this.resizeColumnElement.style.minWidth || 15;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (columnWidth + delta > parseInt(minWidth, 10)) {
|
|
|
|
if (this.columnResizeMode === 'fit') {
|
|
|
|
let nextColumn = this.resizeColumnElement.nextElementSibling;
|
|
|
|
let nextColumnWidth = nextColumn.offsetWidth - delta;
|
|
|
|
|
|
|
|
if (newColumnWidth > 15 && nextColumnWidth > 15) {
|
|
|
|
this.resizeTableCells(newColumnWidth, nextColumnWidth);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.columnResizeMode === 'expand') {
|
2022-09-06 12:03:37 +00:00
|
|
|
const tableWidth = this.$refs.table.offsetWidth + delta + 'px';
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
const updateTableWidth = (el) => {
|
|
|
|
!!el && (el.style.width = el.style.minWidth = tableWidth);
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
updateTableWidth(this.$refs.table);
|
|
|
|
|
|
|
|
if (!this.virtualScrollerDisabled) {
|
|
|
|
const body = this.$refs.bodyRef && this.$refs.bodyRef.$el;
|
|
|
|
const frozenBody = this.$refs.frozenBodyRef && this.$refs.frozenBodyRef.$el;
|
|
|
|
|
|
|
|
updateTableWidth(body);
|
|
|
|
updateTableWidth(frozenBody);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.resizeTableCells(newColumnWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('column-resize-end', {
|
|
|
|
element: this.resizeColumnElement,
|
|
|
|
delta: delta
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$refs.resizeHelper.style.display = 'none';
|
|
|
|
this.resizeColumn = null;
|
2023-06-09 12:44:26 +00:00
|
|
|
this.$el.setAttribute('data-p-unselectable-text', 'true');
|
|
|
|
!this.isUnstyled && DomHandler.removeClass(this.$el, 'p-unselectable-text');
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.unbindColumnResizeEvents();
|
|
|
|
|
|
|
|
if (this.isStateful()) {
|
|
|
|
this.saveState();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resizeTableCells(newColumnWidth, nextColumnWidth) {
|
|
|
|
let colIndex = DomHandler.index(this.resizeColumnElement);
|
|
|
|
let widths = [];
|
2023-06-02 06:52:13 +00:00
|
|
|
let headers = DomHandler.find(this.$refs.table, 'thead[data-pc-section="thead"] > tr > th');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
headers.forEach((header) => widths.push(DomHandler.getOuterWidth(header)));
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.destroyStyleElement();
|
|
|
|
this.createStyleElement();
|
|
|
|
|
|
|
|
let innerHTML = '';
|
2023-06-02 06:52:13 +00:00
|
|
|
let selector = `[data-pc-name="datatable"][${this.attributeSelector}] > [data-pc-section="wrapper"] ${this.virtualScrollerDisabled ? '' : '> [data-pc-section="virtualscroller"]'} > table[data-pc-section="table"]`;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
widths.forEach((width, index) => {
|
2022-09-14 11:26:01 +00:00
|
|
|
let colWidth = index === colIndex ? newColumnWidth : nextColumnWidth && index === colIndex + 1 ? nextColumnWidth : width;
|
2023-02-28 10:33:00 +00:00
|
|
|
let style = `width: ${colWidth}px !important; max-width: ${colWidth}px !important`;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
innerHTML += `
|
2023-06-02 06:52:13 +00:00
|
|
|
${selector} > thead[data-pc-section="thead"] > tr > th:nth-child(${index + 1}),
|
|
|
|
${selector} > tbody[data-pc-section="tbody"] > tr > td:nth-child(${index + 1}),
|
|
|
|
${selector} > tfoot[data-pc-section="tfoot"] > tr > td:nth-child(${index + 1}) {
|
2022-09-06 12:03:37 +00:00
|
|
|
${style}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
`;
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.styleElement.innerHTML = innerHTML;
|
|
|
|
},
|
|
|
|
bindColumnResizeEvents() {
|
|
|
|
if (!this.documentColumnResizeListener) {
|
|
|
|
this.documentColumnResizeListener = document.addEventListener('mousemove', () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.columnResizing) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.onColumnResize(event);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.documentColumnResizeEndListener) {
|
|
|
|
this.documentColumnResizeEndListener = document.addEventListener('mouseup', () => {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.columnResizing) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.columnResizing = false;
|
|
|
|
this.onColumnResizeEnd();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
unbindColumnResizeEvents() {
|
|
|
|
if (this.documentColumnResizeListener) {
|
|
|
|
document.removeEventListener('document', this.documentColumnResizeListener);
|
|
|
|
this.documentColumnResizeListener = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.documentColumnResizeEndListener) {
|
|
|
|
document.removeEventListener('document', this.documentColumnResizeEndListener);
|
|
|
|
this.documentColumnResizeEndListener = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderMouseDown(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const column = e.column;
|
|
|
|
|
|
|
|
if (this.reorderableColumns && this.columnProp(column, 'reorderableColumn') !== false) {
|
2023-06-02 06:52:13 +00:00
|
|
|
if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA' || DomHandler.getAttribute(event.target, '[data-pc-section="columnresizer"]')) event.currentTarget.draggable = false;
|
2022-09-14 11:26:01 +00:00
|
|
|
else event.currentTarget.draggable = true;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderDragStart(event) {
|
|
|
|
if (this.columnResizing) {
|
|
|
|
event.preventDefault();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
if (this.reorderableColumns && this.draggedColumn && dropHeader) {
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
let containerOffset = DomHandler.getOffset(this.$el);
|
|
|
|
let dropHeaderOffset = DomHandler.getOffset(dropHeader);
|
|
|
|
|
|
|
|
if (this.draggedColumn !== dropHeader) {
|
2022-09-14 11:26:01 +00:00
|
|
|
let targetLeft = dropHeaderOffset.left - containerOffset.left;
|
2022-09-06 12:03:37 +00:00
|
|
|
let columnCenter = dropHeaderOffset.left + dropHeader.offsetWidth / 2;
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
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';
|
2022-09-06 12:03:37 +00:00
|
|
|
this.dropPosition = 1;
|
2022-09-14 11:26:01 +00:00
|
|
|
} 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';
|
2022-09-06 12:03:37 +00:00
|
|
|
this.dropPosition = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$refs.reorderIndicatorUp.style.display = 'block';
|
|
|
|
this.$refs.reorderIndicatorDown.style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderDragLeave(event) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.reorderableColumns && this.draggedColumn) {
|
2022-09-06 12:03:37 +00:00
|
|
|
event.preventDefault();
|
|
|
|
this.$refs.reorderIndicatorUp.style.display = 'none';
|
|
|
|
this.$refs.reorderIndicatorDown.style.display = 'none';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onColumnHeaderDrop(event) {
|
|
|
|
event.preventDefault();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.draggedColumn) {
|
|
|
|
let dragIndex = DomHandler.index(this.draggedColumn);
|
|
|
|
let dropIndex = DomHandler.index(this.findParentHeader(event.target));
|
2022-09-14 11:26:01 +00:00
|
|
|
let allowDrop = dragIndex !== dropIndex;
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (allowDrop && ((dropIndex - dragIndex === 1 && this.dropPosition === -1) || (dropIndex - dragIndex === -1 && this.dropPosition === 1))) {
|
|
|
|
allowDrop = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allowDrop) {
|
|
|
|
ObjectUtils.reorderArray(this.columns, dragIndex, dropIndex);
|
|
|
|
this.updateReorderableColumns();
|
|
|
|
|
|
|
|
this.$emit('column-reorder', {
|
|
|
|
originalEvent: event,
|
|
|
|
dragIndex: dragIndex,
|
|
|
|
dropIndex: dropIndex
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$refs.reorderIndicatorUp.style.display = 'none';
|
|
|
|
this.$refs.reorderIndicatorDown.style.display = 'none';
|
|
|
|
this.draggedColumn.draggable = false;
|
|
|
|
this.draggedColumn = null;
|
|
|
|
this.dropPosition = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
findParentHeader(element) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (element.nodeName === 'TH') {
|
2022-09-06 12:03:37 +00:00
|
|
|
return element;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let parent = element.parentElement;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
while (parent.nodeName !== 'TH') {
|
2022-09-06 12:03:37 +00:00
|
|
|
parent = parent.parentElement;
|
|
|
|
if (!parent) break;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
findColumnByKey(columns, key) {
|
|
|
|
if (columns && columns.length) {
|
|
|
|
for (let i = 0; i < columns.length; i++) {
|
|
|
|
let column = columns[i];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.columnProp(column, 'columnKey') === key || this.columnProp(column, 'field') === key) {
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
onRowMouseDown(event) {
|
2023-06-02 06:52:13 +00:00
|
|
|
if (DomHandler.getAttribute(event.target, 'data-pc-section') === 'rowreordericon') event.currentTarget.draggable = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
else event.currentTarget.draggable = false;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDragStart(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const index = e.index;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.rowDragging = true;
|
|
|
|
this.draggedRowIndex = index;
|
2022-09-14 11:26:01 +00:00
|
|
|
event.dataTransfer.setData('text', 'b'); // For firefox
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDragOver(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const index = e.index;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (pageY < rowMidY) {
|
2023-06-09 12:44:26 +00:00
|
|
|
rowElement.setAttribute('data-p-datatable-dragpoint-bottom', 'false');
|
|
|
|
!this.isUnstyled && DomHandler.removeClass(rowElement, 'p-datatable-dragpoint-bottom');
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.droppedRowIndex = index;
|
2023-06-09 12:44:26 +00:00
|
|
|
|
|
|
|
if (prevRowElement) {
|
|
|
|
prevRowElement.setAttribute('data-p-datatable-dragpoint-bottom', 'true');
|
|
|
|
!this.isUnstyled && DomHandler.addClass(prevRowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
} else {
|
|
|
|
rowElement.setAttribute('data-p-datatable-dragpoint-top', 'true');
|
|
|
|
!this.isUnstyled && DomHandler.addClass(rowElement, 'p-datatable-dragpoint-top');
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2023-06-09 12:44:26 +00:00
|
|
|
if (prevRowElement) {
|
|
|
|
prevRowElement.setAttribute('data-p-datatable-dragpoint-bottom', 'false');
|
|
|
|
!this.isUnstyled && DomHandler.removeClass(prevRowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
} else {
|
|
|
|
rowElement.setAttribute('data-p-datatable-dragpoint-top', 'true');
|
|
|
|
!this.isUnstyled && DomHandler.addClass(rowElement, 'p-datatable-dragpoint-top');
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.droppedRowIndex = index + 1;
|
2023-06-09 12:44:26 +00:00
|
|
|
rowElement.setAttribute('data-p-datatable-dragpoint-bottom', 'true');
|
|
|
|
!this.isUnstyled && DomHandler.addClass(rowElement, 'p-datatable-dragpoint-bottom');
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onRowDragLeave(event) {
|
|
|
|
let rowElement = event.currentTarget;
|
|
|
|
let prevRowElement = rowElement.previousElementSibling;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevRowElement) {
|
2023-06-09 12:44:26 +00:00
|
|
|
prevRowElement.setAttribute('data-p-datatable-dragpoint-bottom', 'false');
|
|
|
|
!this.isUnstyled && DomHandler.removeClass(prevRowElement, 'p-datatable-dragpoint-bottom');
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
2023-06-09 12:44:26 +00:00
|
|
|
rowElement.setAttribute('data-p-datatable-dragpoint-bottom', 'false');
|
|
|
|
!this.isUnstyled && DomHandler.removeClass(rowElement, 'p-datatable-dragpoint-bottom');
|
|
|
|
rowElement.setAttribute('data-p-datatable-dragpoint-top', 'false');
|
|
|
|
!this.isUnstyled && DomHandler.removeClass(rowElement, 'p-datatable-dragpoint-top');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDragEnd(event) {
|
|
|
|
this.rowDragging = false;
|
|
|
|
this.draggedRowIndex = null;
|
|
|
|
this.droppedRowIndex = null;
|
|
|
|
event.currentTarget.draggable = false;
|
|
|
|
},
|
|
|
|
onRowDrop(event) {
|
|
|
|
if (this.droppedRowIndex != null) {
|
2022-09-14 11:26:01 +00:00
|
|
|
let dropIndex = this.draggedRowIndex > this.droppedRowIndex ? this.droppedRowIndex : this.droppedRowIndex === 0 ? 0 : this.droppedRowIndex - 1;
|
2022-09-06 12:03:37 +00:00
|
|
|
let processedData = [...this.processedData];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-01-07 00:22:05 +00:00
|
|
|
ObjectUtils.reorderArray(processedData, this.draggedRowIndex + this.d_first, dropIndex + this.d_first);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.$emit('row-reorder', {
|
|
|
|
originalEvent: event,
|
|
|
|
dragIndex: this.draggedRowIndex,
|
|
|
|
dropIndex: dropIndex,
|
|
|
|
value: processedData
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
this.onRowDragLeave(event);
|
|
|
|
this.onRowDragEnd(event);
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
toggleRow(event) {
|
|
|
|
let rowData = event.data;
|
|
|
|
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;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
expandedRowIndex = this.findIndex(rowData, this.expandedRows);
|
|
|
|
expanded = expandedRowIndex > -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expanded) {
|
|
|
|
if (expandedRowIndex == null) {
|
|
|
|
expandedRowIndex = this.findIndex(rowData, this.expandedRows);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_expandedRows.splice(expandedRowIndex, 1);
|
|
|
|
this.$emit('update:expandedRows', _expandedRows);
|
|
|
|
this.$emit('row-collapse', event);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
_expandedRows.push(rowData);
|
|
|
|
this.$emit('update:expandedRows', _expandedRows);
|
|
|
|
this.$emit('row-expand', event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleRowGroup(e) {
|
|
|
|
const event = e.originalEvent;
|
|
|
|
const data = e.data;
|
|
|
|
const groupFieldValue = ObjectUtils.resolveFieldData(data, this.groupRowsBy);
|
|
|
|
let _expandedRowGroups = this.expandedRowGroups ? [...this.expandedRowGroups] : [];
|
|
|
|
|
|
|
|
if (this.isRowGroupExpanded(data)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
_expandedRowGroups = _expandedRowGroups.filter((group) => group !== groupFieldValue);
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('update:expandedRowGroups', _expandedRowGroups);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('rowgroup-collapse', { originalEvent: event, data: groupFieldValue });
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
_expandedRowGroups.push(groupFieldValue);
|
|
|
|
this.$emit('update:expandedRowGroups', _expandedRowGroups);
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('rowgroup-expand', { originalEvent: event, data: groupFieldValue });
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
isRowGroupExpanded(rowData) {
|
|
|
|
if (this.expandableRowGroups && this.expandedRowGroups) {
|
|
|
|
let groupFieldValue = ObjectUtils.resolveFieldData(rowData, this.groupRowsBy);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return this.expandedRowGroups.indexOf(groupFieldValue) > -1;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isStateful() {
|
|
|
|
return this.stateKey != null;
|
|
|
|
},
|
|
|
|
getStorage() {
|
2022-09-14 11:26:01 +00:00
|
|
|
switch (this.stateStorage) {
|
2022-09-06 12:03:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.hasFilters) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('state-save', state);
|
|
|
|
},
|
|
|
|
restoreState() {
|
|
|
|
const storage = this.getStorage();
|
|
|
|
const stateString = storage.getItem(this.stateKey);
|
|
|
|
const dateFormat = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
const reviver = function (key, value) {
|
|
|
|
if (typeof value === 'string' && dateFormat.test(value)) {
|
2022-09-06 12:03:37 +00:00
|
|
|
return new Date(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
if (stateString) {
|
|
|
|
let restoredState = JSON.parse(stateString, reviver);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restoredState.selection) {
|
|
|
|
this.d_selectionKeys = restoredState.d_selectionKeys;
|
|
|
|
this.$emit('update:selection', restoredState.selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('state-restore', restoredState);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
saveColumnWidths(state) {
|
|
|
|
let widths = [];
|
2023-06-02 06:52:13 +00:00
|
|
|
let headers = DomHandler.find(this.$el, 'thead[data-pc-section="thead"] > tr > th');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
headers.forEach((header) => widths.push(DomHandler.getOuterWidth(header)));
|
2022-09-06 12:03:37 +00:00
|
|
|
state.columnWidths = widths.join(',');
|
|
|
|
|
|
|
|
if (this.columnResizeMode === 'expand') {
|
|
|
|
state.tableWidth = DomHandler.getOuterWidth(this.$refs.table) + 'px';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
restoreColumnWidths() {
|
|
|
|
if (this.columnWidthsState) {
|
|
|
|
let widths = this.columnWidthsState.split(',');
|
|
|
|
|
|
|
|
if (this.columnResizeMode === 'expand' && this.tableWidthState) {
|
|
|
|
this.$refs.table.style.width = this.tableWidthState;
|
|
|
|
this.$refs.table.style.minWidth = this.tableWidthState;
|
|
|
|
this.$el.style.width = this.tableWidthState;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjectUtils.isNotEmpty(widths)) {
|
|
|
|
this.createStyleElement();
|
|
|
|
|
|
|
|
let innerHTML = '';
|
2023-06-02 06:52:13 +00:00
|
|
|
let selector = `[data-pc-name="datatable"][${this.attributeSelector}] > [data-pc-section="wrapper"] ${this.virtualScrollerDisabled ? '' : '> [data-pc-section="virtualscroller"]'} > table[data-pc-section="table"]`;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
widths.forEach((width, index) => {
|
2023-02-28 10:33:00 +00:00
|
|
|
let style = `width: ${width}px !important; max-width: ${width}px !important`;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
innerHTML += `
|
2023-06-02 06:52:13 +00:00
|
|
|
${selector} > thead[data-pc-section="thead"] > tr > th:nth-child(${index + 1}),
|
|
|
|
${selector} > tbody[data-pc-section="tbody"] > tr > td:nth-child(${index + 1}),
|
|
|
|
${selector} > tfoot[data-pc-section="tfoot"] > tr > td:nth-child(${index + 1}) {
|
2022-09-06 12:03:37 +00:00
|
|
|
${style}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
`;
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.styleElement.innerHTML = innerHTML;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onCellEditInit(event) {
|
|
|
|
this.$emit('cell-edit-init', event);
|
|
|
|
},
|
|
|
|
onCellEditComplete(event) {
|
|
|
|
this.$emit('cell-edit-complete', event);
|
|
|
|
},
|
|
|
|
onCellEditCancel(event) {
|
|
|
|
this.$emit('cell-edit-cancel', event);
|
|
|
|
},
|
|
|
|
onRowEditInit(event) {
|
|
|
|
let _editingRows = this.editingRows ? [...this.editingRows] : [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_editingRows.push(event.data);
|
|
|
|
this.$emit('update:editingRows', _editingRows);
|
|
|
|
this.$emit('row-edit-init', event);
|
|
|
|
},
|
|
|
|
onRowEditSave(event) {
|
|
|
|
let _editingRows = [...this.editingRows];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_editingRows.splice(this.findIndex(event.data, _editingRows), 1);
|
|
|
|
this.$emit('update:editingRows', _editingRows);
|
|
|
|
this.$emit('row-edit-save', event);
|
|
|
|
},
|
|
|
|
onRowEditCancel(event) {
|
|
|
|
let _editingRows = [...this.editingRows];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
_editingRows.splice(this.findIndex(event.data, _editingRows), 1);
|
|
|
|
this.$emit('update:editingRows', _editingRows);
|
|
|
|
this.$emit('row-edit-cancel', event);
|
|
|
|
},
|
|
|
|
onEditingMetaChange(event) {
|
|
|
|
let { data, field, index, editing } = event;
|
|
|
|
let editingMeta = { ...this.d_editingMeta };
|
|
|
|
let meta = editingMeta[index];
|
|
|
|
|
|
|
|
if (editing) {
|
|
|
|
!meta && (meta = editingMeta[index] = { data: { ...data }, fields: [] });
|
|
|
|
meta['fields'].push(field);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (meta) {
|
|
|
|
const fields = meta['fields'].filter((f) => f !== field);
|
|
|
|
|
|
|
|
!fields.length ? delete editingMeta[index] : (meta['fields'] = fields);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.d_editingMeta = editingMeta;
|
|
|
|
},
|
|
|
|
clearEditingMetaData() {
|
|
|
|
if (this.editMode) {
|
|
|
|
this.d_editingMeta = {};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
createLazyLoadEvent(event) {
|
|
|
|
return {
|
|
|
|
originalEvent: event,
|
|
|
|
first: this.d_first,
|
|
|
|
rows: this.d_rows,
|
|
|
|
sortField: this.d_sortField,
|
|
|
|
sortOrder: this.d_sortOrder,
|
|
|
|
multiSortMeta: this.d_multiSortMeta,
|
|
|
|
filters: this.d_filters
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasGlobalFilter() {
|
|
|
|
return this.filters && Object.prototype.hasOwnProperty.call(this.filters, 'global');
|
|
|
|
},
|
|
|
|
getChildren() {
|
|
|
|
return this.$slots.default ? this.$slots.default() : null;
|
|
|
|
},
|
|
|
|
onFilterChange(filters) {
|
|
|
|
this.d_filters = filters;
|
|
|
|
},
|
|
|
|
onFilterApply() {
|
|
|
|
this.d_first = 0;
|
|
|
|
this.$emit('update:first', this.d_first);
|
|
|
|
this.$emit('update:filters', this.d_filters);
|
|
|
|
|
|
|
|
if (this.lazy) {
|
|
|
|
this.$emit('filter', this.createLazyLoadEvent());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cloneFilters() {
|
|
|
|
let cloned = {};
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.filters) {
|
2022-09-14 11:26:01 +00:00
|
|
|
Object.entries(this.filters).forEach(([prop, value]) => {
|
|
|
|
cloned[prop] = value.operator
|
|
|
|
? {
|
|
|
|
operator: value.operator,
|
|
|
|
constraints: value.constraints.map((constraint) => {
|
|
|
|
return { ...constraint };
|
|
|
|
})
|
|
|
|
}
|
|
|
|
: { ...value };
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return cloned;
|
|
|
|
},
|
|
|
|
updateReorderableColumns() {
|
|
|
|
let columnOrder = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
this.columns.forEach((col) => columnOrder.push(this.columnProp(col, 'columnKey') || this.columnProp(col, 'field')));
|
2022-09-06 12:03:37 +00:00
|
|
|
this.d_columnOrder = columnOrder;
|
|
|
|
},
|
|
|
|
createStyleElement() {
|
|
|
|
this.styleElement = document.createElement('style');
|
|
|
|
this.styleElement.type = 'text/css';
|
|
|
|
document.head.appendChild(this.styleElement);
|
|
|
|
},
|
|
|
|
createResponsiveStyle() {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (!this.responsiveStyleElement) {
|
|
|
|
this.responsiveStyleElement = document.createElement('style');
|
|
|
|
this.responsiveStyleElement.type = 'text/css';
|
|
|
|
document.head.appendChild(this.responsiveStyleElement);
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2023-02-28 10:33:00 +00:00
|
|
|
let tableSelector = `.p-datatable-wrapper ${this.virtualScrollerDisabled ? '' : '> .p-virtualscroller'} > .p-datatable-table`;
|
|
|
|
let selector = `.p-datatable[${this.attributeSelector}] > ${tableSelector}`;
|
|
|
|
let gridLinesSelector = `.p-datatable[${this.attributeSelector}].p-datatable-gridlines > ${tableSelector}`;
|
2022-09-06 12:03:37 +00:00
|
|
|
let innerHTML = `
|
|
|
|
@media screen and (max-width: ${this.breakpoint}) {
|
2023-02-28 10:33:00 +00:00
|
|
|
${selector} > .p-datatable-thead > tr > th,
|
|
|
|
${selector} > .p-datatable-tfoot > tr > td {
|
2022-09-06 12:03:37 +00:00
|
|
|
display: none !important;
|
|
|
|
}
|
|
|
|
|
2023-02-28 10:33:00 +00:00
|
|
|
${selector} > .p-datatable-tbody > tr > td {
|
2022-09-06 12:03:37 +00:00
|
|
|
display: flex;
|
|
|
|
width: 100% !important;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
}
|
|
|
|
|
2023-02-28 10:33:00 +00:00
|
|
|
${selector} > .p-datatable-tbody > tr > td:not(:last-child) {
|
2022-09-06 12:03:37 +00:00
|
|
|
border: 0 none;
|
|
|
|
}
|
|
|
|
|
2023-02-28 10:33:00 +00:00
|
|
|
${gridLinesSelector} > .p-datatable-tbody > tr > td:last-child {
|
2022-09-06 12:03:37 +00:00
|
|
|
border-top: 0;
|
|
|
|
border-right: 0;
|
|
|
|
border-left: 0;
|
|
|
|
}
|
|
|
|
|
2023-02-28 10:33:00 +00:00
|
|
|
${selector} > .p-datatable-tbody > tr > td > .p-column-title {
|
2022-09-06 12:03:37 +00:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
this.responsiveStyleElement.innerHTML = innerHTML;
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
destroyResponsiveStyle() {
|
|
|
|
if (this.responsiveStyleElement) {
|
|
|
|
document.head.removeChild(this.responsiveStyleElement);
|
|
|
|
this.responsiveStyleElement = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
destroyStyleElement() {
|
|
|
|
if (this.styleElement) {
|
|
|
|
document.head.removeChild(this.styleElement);
|
|
|
|
this.styleElement = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
recursiveGetChildren(children, results) {
|
|
|
|
if (!results) {
|
|
|
|
results = [];
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (children && children.length) {
|
|
|
|
children.forEach((child) => {
|
|
|
|
if (child.children instanceof Array) {
|
|
|
|
results.concat(this.recursiveGetChildren(child.children, results));
|
|
|
|
} else if (child.type.name == 'Column') {
|
|
|
|
results.push(child);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return results;
|
|
|
|
},
|
|
|
|
dataToRender(data) {
|
|
|
|
const _data = data || this.processedData;
|
|
|
|
|
|
|
|
if (_data && this.paginator) {
|
|
|
|
const first = this.lazy ? 0 : this.d_first;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return _data.slice(first, first + this.d_rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _data;
|
|
|
|
},
|
|
|
|
getVirtualScrollerRef() {
|
|
|
|
return this.$refs.virtualScroller;
|
2023-02-28 10:33:00 +00:00
|
|
|
},
|
|
|
|
hasSpacerStyle(style) {
|
|
|
|
return ObjectUtils.isNotEmpty(style);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
columns() {
|
|
|
|
let children = this.getChildren();
|
|
|
|
|
|
|
|
if (!children) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cols = this.recursiveGetChildren(children, []);
|
|
|
|
|
|
|
|
if (this.reorderableColumns && this.d_columnOrder) {
|
|
|
|
let orderedColumns = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let columnKey of this.d_columnOrder) {
|
|
|
|
let column = this.findColumnByKey(cols, columnKey);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (column && !this.columnProp(column, 'hidden')) {
|
|
|
|
orderedColumns.push(column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [...orderedColumns, ...cols.filter((item) => orderedColumns.indexOf(item) < 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cols;
|
|
|
|
},
|
|
|
|
headerColumnGroup() {
|
|
|
|
const children = this.getChildren();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (children) {
|
|
|
|
for (let child of children) {
|
|
|
|
if (child.type.name === 'ColumnGroup' && this.columnProp(child, 'type') === 'header') {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
footerColumnGroup() {
|
|
|
|
const children = this.getChildren();
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (children) {
|
|
|
|
for (let child of children) {
|
|
|
|
if (child.type.name === 'ColumnGroup' && this.columnProp(child, 'type') === 'footer') {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
hasFilters() {
|
|
|
|
return this.filters && Object.keys(this.filters).length > 0 && this.filters.constructor === Object;
|
|
|
|
},
|
|
|
|
processedData() {
|
|
|
|
let data = this.value || [];
|
|
|
|
|
|
|
|
if (!this.lazy) {
|
|
|
|
if (data && data.length) {
|
|
|
|
if (this.hasFilters) {
|
|
|
|
data = this.filter(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.sorted) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.sortMode === 'single') data = this.sortSingle(data);
|
|
|
|
else if (this.sortMode === 'multiple') data = this.sortMultiple(data);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
totalRecordsLength() {
|
|
|
|
if (this.lazy) {
|
|
|
|
return this.totalRecords;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
const data = this.processedData;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return data ? data.length : 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
empty() {
|
|
|
|
const data = this.processedData;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
return !data || data.length === 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
paginatorTop() {
|
|
|
|
return this.paginator && (this.paginatorPosition !== 'bottom' || this.paginatorPosition === 'both');
|
|
|
|
},
|
|
|
|
paginatorBottom() {
|
|
|
|
return this.paginator && (this.paginatorPosition !== 'top' || this.paginatorPosition === 'both');
|
|
|
|
},
|
|
|
|
sorted() {
|
|
|
|
return this.d_sortField || (this.d_multiSortMeta && this.d_multiSortMeta.length > 0);
|
|
|
|
},
|
|
|
|
allRowsSelected() {
|
|
|
|
if (this.selectAll !== null) {
|
|
|
|
return this.selectAll;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
const val = this.frozenValue ? [...this.frozenValue, ...this.processedData] : this.processedData;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
return ObjectUtils.isNotEmpty(val) && this.selection && Array.isArray(this.selection) && val.every((v) => this.selection.some((s) => this.equals(s, v)));
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
attributeSelector() {
|
|
|
|
return UniqueComponentId();
|
|
|
|
},
|
|
|
|
groupRowSortField() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.sortMode === 'single' ? this.sortField : this.d_groupRowsSortMeta ? this.d_groupRowsSortMeta.field : null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
virtualScrollerDisabled() {
|
|
|
|
return ObjectUtils.isEmpty(this.virtualScrollerOptions) || !this.scrollable;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
DTPaginator: Paginator,
|
|
|
|
DTTableHeader: TableHeader,
|
|
|
|
DTTableBody: TableBody,
|
|
|
|
DTTableFooter: TableFooter,
|
2023-04-13 14:42:33 +00:00
|
|
|
DTVirtualScroller: VirtualScroller,
|
|
|
|
ArrowDownIcon: ArrowDownIcon,
|
|
|
|
ArrowUpIcon: ArrowUpIcon,
|
|
|
|
SpinnerIcon: SpinnerIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|