2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-07-19 12:05:06 +00:00
|
|
|
<tbody :ref="bodyRef" :class="cx('tbody')" role="rowgroup" :style="bodyStyle" v-bind="ptm('tbody', ptmTBodyOptions)">
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!empty">
|
2023-03-27 08:37:20 +00:00
|
|
|
<template v-for="(rowData, index) of value">
|
|
|
|
<tr
|
|
|
|
v-if="templates['groupheader'] && rowGroupMode === 'subheader' && shouldRenderRowGroupHeader(value, rowData, getRowIndex(index))"
|
|
|
|
:key="getRowKey(rowData, getRowIndex(index)) + '_subheader'"
|
2023-06-08 11:26:48 +00:00
|
|
|
:class="cx('rowGroupHeader')"
|
2023-03-27 08:37:20 +00:00
|
|
|
:style="rowGroupHeaderStyle"
|
|
|
|
role="row"
|
2023-06-05 13:49:36 +00:00
|
|
|
v-bind="ptm('rowGroupHeader')"
|
2023-03-27 08:37:20 +00:00
|
|
|
>
|
2023-09-01 10:06:53 +00:00
|
|
|
<td :colspan="columnsLength - 1" v-bind="{ ...getColumnPT('bodycell'), ...ptm('rowGroupHeaderCell') }">
|
2023-07-19 12:05:06 +00:00
|
|
|
<button v-if="expandableRowGroups" :class="cx('rowGroupToggler')" @click="onRowGroupToggle($event, rowData)" type="button" v-bind="ptm('rowGroupToggler')">
|
2023-04-13 14:42:33 +00:00
|
|
|
<component v-if="templates['rowgrouptogglericon']" :is="templates['rowgrouptogglericon']" :expanded="isRowGroupExpanded(rowData)" />
|
2023-04-18 10:51:10 +00:00
|
|
|
<template v-else>
|
2023-07-19 12:05:06 +00:00
|
|
|
<span v-if="isRowGroupExpanded(rowData) && expandedRowIcon" :class="[cx('rowGroupTogglerIcon'), expandedRowIcon]" v-bind="ptm('rowGroupTogglerIcon')" />
|
|
|
|
<ChevronDownIcon v-else-if="isRowGroupExpanded(rowData) && !expandedRowIcon" :class="cx('rowGroupTogglerIcon')" v-bind="ptm('rowGroupTogglerIcon')" />
|
|
|
|
<span v-else-if="!isRowGroupExpanded(rowData) && collapsedRowIcon" :class="[cx('rowGroupTogglerIcon'), collapsedRowIcon]" v-bind="ptm('rowGroupTogglerIcon')" />
|
|
|
|
<ChevronRightIcon v-else-if="!isRowGroupExpanded(rowData) && !collapsedRowIcon" :class="cx('rowGroupTogglerIcon')" v-bind="ptm('rowGroupTogglerIcon')" />
|
2023-04-18 10:51:10 +00:00
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
|
|
|
<component :is="templates['groupheader']" :data="rowData" :index="getRowIndex(index)" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
2022-09-14 11:26:01 +00:00
|
|
|
<tr
|
|
|
|
v-if="expandableRowGroups ? isRowGroupExpanded(rowData) : true"
|
|
|
|
:key="getRowKey(rowData, getRowIndex(index))"
|
|
|
|
:class="getRowClass(rowData)"
|
2023-03-13 07:56:32 +00:00
|
|
|
:style="getRowStyle(rowData)"
|
2022-12-08 11:04:25 +00:00
|
|
|
:tabindex="setRowTabindex(index)"
|
|
|
|
role="row"
|
|
|
|
:aria-selected="selectionMode ? isSelected(rowData) : null"
|
2022-09-14 11:26:01 +00:00
|
|
|
@click="onRowClick($event, rowData, getRowIndex(index))"
|
|
|
|
@dblclick="onRowDblClick($event, rowData, getRowIndex(index))"
|
|
|
|
@contextmenu="onRowRightClick($event, rowData, getRowIndex(index))"
|
|
|
|
@touchend="onRowTouchEnd($event)"
|
2023-09-05 01:52:13 +00:00
|
|
|
@keydown.self="onRowKeyDown($event, rowData, getRowIndex(index))"
|
2022-09-14 11:26:01 +00:00
|
|
|
@mousedown="onRowMouseDown($event)"
|
|
|
|
@dragstart="onRowDragStart($event, getRowIndex(index))"
|
|
|
|
@dragover="onRowDragOver($event, getRowIndex(index))"
|
|
|
|
@dragleave="onRowDragLeave($event)"
|
|
|
|
@dragend="onRowDragEnd($event)"
|
|
|
|
@drop="onRowDrop($event)"
|
2023-07-19 12:05:06 +00:00
|
|
|
v-bind="getBodyRowPTOptions('bodyRow', rowData, index)"
|
2023-06-02 06:52:13 +00:00
|
|
|
:data-p-selectable-row="selectionMode ? true : false"
|
|
|
|
:data-p-highlight="selection && isSelected(rowData)"
|
|
|
|
:data-p-highlight-contextmenu="contextMenuSelection && isSelectedWithContextMenu(rowData)"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
2023-03-27 08:37:20 +00:00
|
|
|
<template v-for="(col, i) of columns">
|
2022-09-14 11:26:01 +00:00
|
|
|
<DTBodyCell
|
|
|
|
v-if="shouldRenderBodyCell(value, col, getRowIndex(index))"
|
2023-03-27 08:37:20 +00:00
|
|
|
:key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i"
|
2022-09-14 11:26:01 +00:00
|
|
|
:rowData="rowData"
|
|
|
|
:column="col"
|
|
|
|
:rowIndex="getRowIndex(index)"
|
|
|
|
:index="i"
|
|
|
|
:selected="isSelected(rowData)"
|
|
|
|
:frozenRow="frozenRow"
|
2022-09-06 12:03:37 +00:00
|
|
|
:rowspan="rowGroupMode === 'rowspan' ? calculateRowGroupSize(value, col, getRowIndex(index)) : null"
|
2022-09-14 11:26:01 +00:00
|
|
|
:editMode="editMode"
|
|
|
|
:editing="editMode === 'row' && isRowEditing(rowData)"
|
2022-12-08 11:04:25 +00:00
|
|
|
:editingMeta="editingMeta"
|
2022-09-14 11:26:01 +00:00
|
|
|
:responsiveLayout="responsiveLayout"
|
2022-12-08 11:04:25 +00:00
|
|
|
:virtualScrollerContentProps="virtualScrollerContentProps"
|
|
|
|
:ariaControls="expandedRowId + '_' + index + '_expansion'"
|
|
|
|
:name="nameAttributeSelector"
|
2023-04-13 14:42:33 +00:00
|
|
|
:isRowExpanded="isRowExpanded(rowData)"
|
|
|
|
:expandedRowIcon="expandedRowIcon"
|
|
|
|
:collapsedRowIcon="collapsedRowIcon"
|
2022-09-14 11:26:01 +00:00
|
|
|
@radio-change="onRadioChange($event)"
|
|
|
|
@checkbox-change="onCheckboxChange($event)"
|
|
|
|
@row-toggle="onRowToggle($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)"
|
|
|
|
@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
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
2023-05-08 14:08:06 +00:00
|
|
|
<tr
|
|
|
|
v-if="templates['expansion'] && expandedRows && isRowExpanded(rowData)"
|
|
|
|
:key="getRowKey(rowData, getRowIndex(index)) + '_expansion'"
|
|
|
|
:id="expandedRowId + '_' + index + '_expansion'"
|
2023-06-08 11:26:48 +00:00
|
|
|
:class="cx('rowExpansion')"
|
2023-05-08 14:08:06 +00:00
|
|
|
role="row"
|
|
|
|
v-bind="ptm('rowExpansion')"
|
|
|
|
>
|
2023-09-01 10:06:53 +00:00
|
|
|
<td :colspan="columnsLength" v-bind="{ ...getColumnPT('bodycell'), ...ptm('rowExpansionCell') }">
|
2022-09-06 12:03:37 +00:00
|
|
|
<component :is="templates['expansion']" :data="rowData" :index="getRowIndex(index)" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
2023-05-08 14:08:06 +00:00
|
|
|
<tr
|
|
|
|
v-if="templates['groupfooter'] && rowGroupMode === 'subheader' && shouldRenderRowGroupFooter(value, rowData, getRowIndex(index))"
|
|
|
|
:key="getRowKey(rowData, getRowIndex(index)) + '_subfooter'"
|
2023-06-08 11:26:48 +00:00
|
|
|
:class="cx('rowGroupFooter')"
|
2023-05-08 14:08:06 +00:00
|
|
|
role="row"
|
2023-06-05 13:49:36 +00:00
|
|
|
v-bind="ptm('rowGroupFooter')"
|
2023-05-08 14:08:06 +00:00
|
|
|
>
|
2023-09-01 10:06:53 +00:00
|
|
|
<td :colspan="columnsLength - 1" v-bind="{ ...getColumnPT('bodycell'), ...ptm('rowGroupFooterCell') }">
|
2023-02-28 10:33:00 +00:00
|
|
|
<component :is="templates['groupfooter']" :data="rowData" :index="getRowIndex(index)" />
|
|
|
|
</td>
|
2022-09-06 12:03:37 +00:00
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
</template>
|
2023-06-08 11:26:48 +00:00
|
|
|
<tr v-else :class="cx('emptyMessage')" role="row" v-bind="ptm('emptyMessage')">
|
2023-09-01 10:06:53 +00:00
|
|
|
<td :colspan="columnsLength" v-bind="{ ...getColumnPT('bodycell'), ...ptm('emptyMessageCell') }">
|
2022-09-14 11:26:01 +00:00
|
|
|
<component v-if="templates.empty" :is="templates.empty" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-08 14:08:06 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-04-18 12:53:43 +00:00
|
|
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
|
|
|
import ChevronRightIcon from 'primevue/icons/chevronright';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
|
2023-09-01 09:26:27 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
import BodyCell from './BodyCell.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TableBody',
|
2023-06-08 11:16:48 +00:00
|
|
|
hostName: 'DataTable',
|
2023-05-08 14:08:06 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-14 11:26:01 +00:00
|
|
|
emits: [
|
|
|
|
'rowgroup-toggle',
|
|
|
|
'row-click',
|
|
|
|
'row-dblclick',
|
|
|
|
'row-rightclick',
|
|
|
|
'row-touchend',
|
|
|
|
'row-keydown',
|
|
|
|
'row-mousedown',
|
|
|
|
'row-dragstart',
|
|
|
|
'row-dragover',
|
|
|
|
'row-dragleave',
|
|
|
|
'row-dragend',
|
|
|
|
'row-drop',
|
|
|
|
'row-toggle',
|
|
|
|
'radio-change',
|
|
|
|
'checkbox-change',
|
|
|
|
'cell-edit-init',
|
|
|
|
'cell-edit-complete',
|
|
|
|
'cell-edit-cancel',
|
|
|
|
'row-edit-init',
|
|
|
|
'row-edit-save',
|
|
|
|
'row-edit-cancel',
|
|
|
|
'editing-meta-change'
|
|
|
|
],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
columns: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
frozenRow: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
empty: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
rowGroupMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
groupRowsBy: {
|
2022-12-08 11:04:25 +00:00
|
|
|
type: [Array, String, Function],
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandableRowGroups: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
expandedRowGroups: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
2023-03-27 08:37:20 +00:00
|
|
|
first: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
dataKey: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedRowIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
collapsedRowIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedRows: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedRowKeys: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
selection: {
|
2022-09-14 11:26:01 +00:00
|
|
|
type: [Array, Object],
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
selectionKeys: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
selectionMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
contextMenu: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
contextMenuSelection: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
rowClass: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
rowStyle: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
editMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
compareSelectionBy: {
|
|
|
|
type: String,
|
|
|
|
default: 'deepEquals'
|
|
|
|
},
|
|
|
|
editingRows: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
editingRowKeys: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
editingMeta: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
scrollable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
responsiveLayout: {
|
|
|
|
type: String,
|
|
|
|
default: 'stack'
|
|
|
|
},
|
|
|
|
virtualScrollerContentProps: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
isVirtualScrollerDisabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2022-12-08 11:04:25 +00:00
|
|
|
rowGroupHeaderStyleObject: {},
|
|
|
|
tabindexArray: [],
|
|
|
|
isARowSelected: false
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
mounted() {
|
|
|
|
if (this.frozenRow) {
|
|
|
|
this.updateFrozenRowStickyPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.scrollable && this.rowGroupMode === 'subheader') {
|
|
|
|
this.updateFrozenRowGroupHeaderStickyPosition();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
if (this.frozenRow) {
|
|
|
|
this.updateFrozenRowStickyPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.scrollable && this.rowGroupMode === 'subheader') {
|
|
|
|
this.updateFrozenRowGroupHeaderStickyPosition();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
columnProp(col, prop) {
|
|
|
|
return ObjectUtils.getVNodeProp(col, prop);
|
|
|
|
},
|
2023-09-01 09:26:27 +00:00
|
|
|
getColumnPT(key) {
|
|
|
|
const columnMetaData = {
|
|
|
|
parent: {
|
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp({}), key, columnMetaData));
|
|
|
|
},
|
2023-05-09 14:57:31 +00:00
|
|
|
getColumnProp(column) {
|
|
|
|
return column.props && column.props.pt ? column.props.pt : undefined; //@todo
|
|
|
|
},
|
2023-07-19 12:05:06 +00:00
|
|
|
getBodyRowPTOptions(key, rowdata, index) {
|
|
|
|
return this.ptm(key, {
|
|
|
|
context: {
|
|
|
|
index,
|
|
|
|
selectable: this.$parentInstance?.$parentInstance?.rowHover || this.$parentInstance?.$parentInstance?.selectionMode,
|
|
|
|
selected: this.isSelected(rowdata),
|
|
|
|
stripedRows: this.$parentInstance?.$parentInstance?.stripedRows || false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
shouldRenderRowGroupHeader(value, rowData, i) {
|
|
|
|
let currentRowFieldData = ObjectUtils.resolveFieldData(rowData, this.groupRowsBy);
|
|
|
|
let prevRowData = value[i - 1];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevRowData) {
|
|
|
|
let previousRowFieldData = ObjectUtils.resolveFieldData(prevRowData, this.groupRowsBy);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return currentRowFieldData !== previousRowFieldData;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getRowKey(rowData, index) {
|
2023-03-27 08:37:20 +00:00
|
|
|
return this.dataKey ? ObjectUtils.resolveFieldData(rowData, this.dataKey) : this.getRowIndex(index);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
getRowIndex(index) {
|
|
|
|
const getItemOptions = this.getVirtualScrollerProp('getItemOptions');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2023-08-18 01:42:05 +00:00
|
|
|
return getItemOptions ? getItemOptions(index).index : index;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-03-13 07:56:32 +00:00
|
|
|
getRowStyle(rowData) {
|
|
|
|
if (this.rowStyle) {
|
|
|
|
return this.rowStyle(rowData);
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
getRowClass(rowData) {
|
|
|
|
let rowStyleClass = [];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.rowClass) {
|
|
|
|
let rowClassValue = this.rowClass(rowData);
|
|
|
|
|
|
|
|
if (rowClassValue) {
|
|
|
|
rowStyleClass.push(rowClassValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 11:26:48 +00:00
|
|
|
return [this.cx('row', { rowData }), rowStyleClass];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
shouldRenderRowGroupFooter(value, rowData, i) {
|
|
|
|
if (this.expandableRowGroups && !this.isRowGroupExpanded(rowData)) {
|
|
|
|
return false;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let currentRowFieldData = ObjectUtils.resolveFieldData(rowData, this.groupRowsBy);
|
|
|
|
let nextRowData = value[i + 1];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextRowData) {
|
|
|
|
let nextRowFieldData = ObjectUtils.resolveFieldData(nextRowData, this.groupRowsBy);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return currentRowFieldData !== nextRowFieldData;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
shouldRenderBodyCell(value, column, i) {
|
|
|
|
if (this.rowGroupMode) {
|
|
|
|
if (this.rowGroupMode === 'subheader') {
|
|
|
|
return this.groupRowsBy !== this.columnProp(column, 'field');
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.rowGroupMode === 'rowspan') {
|
2022-09-06 12:03:37 +00:00
|
|
|
if (this.isGrouped(column)) {
|
|
|
|
let prevRowData = value[i - 1];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prevRowData) {
|
|
|
|
let currentRowFieldData = ObjectUtils.resolveFieldData(value[i], this.columnProp(column, 'field'));
|
|
|
|
let previousRowFieldData = ObjectUtils.resolveFieldData(prevRowData, this.columnProp(column, 'field'));
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return currentRowFieldData !== previousRowFieldData;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return !this.columnProp(column, 'hidden');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
calculateRowGroupSize(value, column, index) {
|
|
|
|
if (this.isGrouped(column)) {
|
|
|
|
let currentRowFieldData = ObjectUtils.resolveFieldData(value[index], this.columnProp(column, 'field'));
|
|
|
|
let nextRowFieldData = currentRowFieldData;
|
|
|
|
let groupRowSpan = 0;
|
|
|
|
|
|
|
|
while (currentRowFieldData === nextRowFieldData) {
|
|
|
|
groupRowSpan++;
|
|
|
|
let nextRowData = value[++index];
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (nextRowData) {
|
|
|
|
nextRowFieldData = ObjectUtils.resolveFieldData(nextRowData, this.columnProp(column, 'field'));
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return groupRowSpan === 1 ? null : groupRowSpan;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isGrouped(column) {
|
|
|
|
if (this.groupRowsBy && this.columnProp(column, 'field')) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (Array.isArray(this.groupRowsBy)) return this.groupRowsBy.indexOf(column.props.field) > -1;
|
|
|
|
else return this.groupRowsBy === column.props.field;
|
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isRowEditing(rowData) {
|
|
|
|
if (rowData && this.editingRows) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.dataKey) return this.editingRowKeys ? this.editingRowKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined : false;
|
|
|
|
else return this.findIndex(rowData, this.editingRows) > -1;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isRowExpanded(rowData) {
|
|
|
|
if (rowData && this.expandedRows) {
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.dataKey) return this.expandedRowKeys ? this.expandedRowKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined : false;
|
|
|
|
else return this.findIndex(rowData, this.expandedRows) > -1;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
isSelected(rowData) {
|
|
|
|
if (rowData && this.selection) {
|
|
|
|
if (this.dataKey) {
|
|
|
|
return this.selectionKeys ? this.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;
|
|
|
|
},
|
|
|
|
isSelectedWithContextMenu(rowData) {
|
|
|
|
if (rowData && this.contextMenuSelection) {
|
|
|
|
return this.equals(rowData, this.contextMenuSelection, this.dataKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
|
|
|
onRowGroupToggle(event, data) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('rowgroup-toggle', { originalEvent: event, data: data });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowClick(event, rowData, rowIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-click', { originalEvent: event, data: rowData, index: rowIndex });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDblClick(event, rowData, rowIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-dblclick', { originalEvent: event, data: rowData, index: rowIndex });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowRightClick(event, rowData, rowIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-rightclick', { originalEvent: event, data: rowData, index: rowIndex });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowTouchEnd(event) {
|
|
|
|
this.$emit('row-touchend', event);
|
|
|
|
},
|
|
|
|
onRowKeyDown(event, rowData, rowIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-keydown', { originalEvent: event, data: rowData, index: rowIndex });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowMouseDown(event) {
|
|
|
|
this.$emit('row-mousedown', event);
|
|
|
|
},
|
|
|
|
onRowDragStart(event, rowIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-dragstart', { originalEvent: event, index: rowIndex });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDragOver(event, rowIndex) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$emit('row-dragover', { originalEvent: event, index: rowIndex });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onRowDragLeave(event) {
|
|
|
|
this.$emit('row-dragleave', event);
|
|
|
|
},
|
|
|
|
onRowDragEnd(event) {
|
|
|
|
this.$emit('row-dragend', event);
|
|
|
|
},
|
|
|
|
onRowDrop(event) {
|
|
|
|
this.$emit('row-drop', event);
|
|
|
|
},
|
|
|
|
onRowToggle(event) {
|
|
|
|
this.$emit('row-toggle', event);
|
|
|
|
},
|
|
|
|
onRadioChange(event) {
|
|
|
|
this.$emit('radio-change', event);
|
|
|
|
},
|
|
|
|
onCheckboxChange(event) {
|
|
|
|
this.$emit('checkbox-change', event);
|
|
|
|
},
|
|
|
|
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) {
|
|
|
|
this.$emit('row-edit-init', event);
|
|
|
|
},
|
|
|
|
onRowEditSave(event) {
|
|
|
|
this.$emit('row-edit-save', event);
|
|
|
|
},
|
|
|
|
onRowEditCancel(event) {
|
|
|
|
this.$emit('row-edit-cancel', event);
|
|
|
|
},
|
|
|
|
onEditingMetaChange(event) {
|
|
|
|
this.$emit('editing-meta-change', event);
|
|
|
|
},
|
|
|
|
updateFrozenRowStickyPosition() {
|
|
|
|
this.$el.style.top = DomHandler.getOuterHeight(this.$el.previousElementSibling) + 'px';
|
|
|
|
},
|
|
|
|
updateFrozenRowGroupHeaderStickyPosition() {
|
|
|
|
let tableHeaderHeight = DomHandler.getOuterHeight(this.$el.previousElementSibling);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
this.rowGroupHeaderStyleObject.top = tableHeaderHeight + 'px';
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
getVirtualScrollerProp(option, options) {
|
|
|
|
options = options || this.virtualScrollerContentProps;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
return options ? options[option] : null;
|
|
|
|
},
|
|
|
|
bodyRef(el) {
|
|
|
|
// For VirtualScroller
|
|
|
|
const contentRef = this.getVirtualScrollerProp('contentRef');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
contentRef && contentRef(el);
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
setRowTabindex(index) {
|
|
|
|
if (this.selection === null && (this.selectionMode === 'single' || this.selectionMode === 'multiple')) {
|
|
|
|
return index === 0 ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
columnsLength() {
|
|
|
|
let hiddenColLength = 0;
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
this.columns.forEach((column) => {
|
2023-03-27 11:47:48 +00:00
|
|
|
if (this.columnProp(column, 'selectionMode') === 'single') hiddenColLength--;
|
2022-09-14 11:26:01 +00:00
|
|
|
if (this.columnProp(column, 'hidden')) hiddenColLength++;
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return this.columns ? this.columns.length - hiddenColLength : 0;
|
|
|
|
},
|
|
|
|
rowGroupHeaderStyle() {
|
|
|
|
if (this.scrollable) {
|
2022-09-14 11:26:01 +00:00
|
|
|
return { top: this.rowGroupHeaderStyleObject.top };
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
bodyStyle() {
|
|
|
|
return this.getVirtualScrollerProp('contentStyle');
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
expandedRowId() {
|
|
|
|
return UniqueComponentId();
|
|
|
|
},
|
|
|
|
nameAttributeSelector() {
|
|
|
|
return UniqueComponentId();
|
2023-07-19 12:05:06 +00:00
|
|
|
},
|
|
|
|
ptmTBodyOptions() {
|
|
|
|
return {
|
|
|
|
context: {
|
|
|
|
scrollable: this.$parentInstance?.$parentInstance?.scrollable
|
|
|
|
}
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2023-04-13 14:42:33 +00:00
|
|
|
DTBodyCell: BodyCell,
|
|
|
|
ChevronDownIcon: ChevronDownIcon,
|
|
|
|
ChevronRightIcon: ChevronRightIcon
|
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>
|