2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-03-14 12:54:35 +00:00
|
|
|
<tbody :ref="bodyRef" :class="cx('tbody')" role="rowgroup" :style="bodyContentStyle" v-bind="ptm('tbody', ptmTBodyOptions)">
|
2022-09-06 12:03:37 +00:00
|
|
|
<template v-if="!empty">
|
2024-02-01 09:19:12 +00:00
|
|
|
<template v-for="(rowData, rowIndex) of value" :key="getRowKey(rowData, rowIndex)">
|
2023-12-18 14:16:35 +00:00
|
|
|
<DTBodyRow
|
|
|
|
:rowData="rowData"
|
|
|
|
:index="rowIndex"
|
|
|
|
:value="value"
|
|
|
|
:columns="columns"
|
|
|
|
:frozenRow="frozenRow"
|
|
|
|
:empty="empty"
|
|
|
|
:first="first"
|
|
|
|
:dataKey="dataKey"
|
|
|
|
:selection="selection"
|
|
|
|
:selectionKeys="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"
|
|
|
|
:expandedRowGroups="expandedRowGroups"
|
|
|
|
:editingRows="editingRows"
|
|
|
|
:editingRowKeys="editingRowKeys"
|
|
|
|
:templates="templates"
|
2024-04-29 09:55:47 +00:00
|
|
|
:editButtonProps="editButtonProps"
|
2023-12-18 14:16:35 +00:00
|
|
|
:responsiveLayout="responsiveLayout"
|
|
|
|
:virtualScrollerContentProps="virtualScrollerContentProps"
|
|
|
|
:isVirtualScrollerDisabled="isVirtualScrollerDisabled"
|
|
|
|
:editingMeta="editingMeta"
|
|
|
|
:rowGroupHeaderStyle="rowGroupHeaderStyle"
|
|
|
|
:expandedRowId="expandedRowId"
|
|
|
|
:nameAttributeSelector="nameAttributeSelector"
|
|
|
|
@rowgroup-toggle="$emit('rowgroup-toggle', $event)"
|
|
|
|
@row-click="$emit('row-click', $event)"
|
|
|
|
@row-dblclick="$emit('row-dblclick', $event)"
|
|
|
|
@row-rightclick="$emit('row-rightclick', $event)"
|
|
|
|
@row-touchend="$emit('row-touchend', $event)"
|
|
|
|
@row-keydown="$emit('row-keydown', $event)"
|
|
|
|
@row-mousedown="$emit('row-mousedown', $event)"
|
|
|
|
@row-dragstart="$emit('row-dragstart', $event)"
|
|
|
|
@row-dragover="$emit('row-dragover', $event)"
|
|
|
|
@row-dragleave="$emit('row-dragleave', $event)"
|
|
|
|
@row-dragend="$emit('row-dragend', $event)"
|
|
|
|
@row-drop="$emit('row-drop', $event)"
|
|
|
|
@row-toggle="$emit('row-toggle', $event)"
|
|
|
|
@radio-change="$emit('radio-change', $event)"
|
|
|
|
@checkbox-change="$emit('checkbox-change', $event)"
|
|
|
|
@cell-edit-init="$emit('cell-edit-init', $event)"
|
|
|
|
@cell-edit-complete="$emit('cell-edit-complete', $event)"
|
|
|
|
@cell-edit-cancel="$emit('cell-edit-cancel', $event)"
|
|
|
|
@row-edit-init="$emit('row-edit-init', $event)"
|
|
|
|
@row-edit-save="$emit('row-edit-save', $event)"
|
|
|
|
@row-edit-cancel="$emit('row-edit-cancel', $event)"
|
|
|
|
@editing-meta-change="$emit('editing-meta-change', $event)"
|
|
|
|
:unstyled="unstyled"
|
|
|
|
:pt="pt"
|
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</template>
|
2023-12-18 14:16:35 +00:00
|
|
|
<DTBodyRow v-else :empty="empty" :columns="columns" :templates="templates" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</tbody>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-08 14:08:06 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2024-02-01 09:19:12 +00:00
|
|
|
import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
|
2023-12-18 14:16:35 +00:00
|
|
|
import BodyRow from './BodyRow.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
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: {
|
2023-09-06 18:13:27 +00:00
|
|
|
type: [String, Function],
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedRowIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
collapsedRowIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
expandedRows: {
|
2023-12-18 14:16:35 +00:00
|
|
|
type: [Array, Object],
|
2022-09-06 12:03:37 +00:00
|
|
|
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
|
|
|
|
},
|
2024-04-29 09:55:47 +00:00
|
|
|
editButtonProps: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
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 {
|
2023-12-18 14:16:35 +00:00
|
|
|
rowGroupHeaderStyleObject: {}
|
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: {
|
2024-02-01 09:19:12 +00:00
|
|
|
getRowKey(rowData, rowIndex) {
|
|
|
|
return this.dataKey ? ObjectUtils.resolveFieldData(rowData, this.dataKey) : rowIndex;
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
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;
|
|
|
|
},
|
2024-03-14 12:54:35 +00:00
|
|
|
bodyContentStyle() {
|
2022-09-06 12:03:37 +00:00
|
|
|
return this.getVirtualScrollerProp('contentStyle');
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
2023-07-19 12:05:06 +00:00
|
|
|
ptmTBodyOptions() {
|
|
|
|
return {
|
|
|
|
context: {
|
|
|
|
scrollable: this.$parentInstance?.$parentInstance?.scrollable
|
|
|
|
}
|
|
|
|
};
|
2023-12-18 14:16:35 +00:00
|
|
|
},
|
|
|
|
expandedRowId() {
|
|
|
|
return UniqueComponentId();
|
|
|
|
},
|
|
|
|
nameAttributeSelector() {
|
|
|
|
return UniqueComponentId();
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2023-12-18 14:16:35 +00:00
|
|
|
DTBodyRow: BodyRow
|
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>
|