primevue-mirror/components/lib/datatable/TableBody.vue

309 lines
9.5 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<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">
<template v-for="(rowData, rowIndex) of value" :key="getRowKey(rowData, rowIndex)">
<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"
:editButtonProps="editButtonProps"
: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>
<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';
import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
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
},
first: {
type: Number,
default: 0
},
2022-09-06 12:03:37 +00:00
dataKey: {
type: [String, Function],
2022-09-06 12:03:37 +00:00
default: null
},
expandedRowIcon: {
type: String,
default: null
},
collapsedRowIcon: {
type: String,
default: null
},
expandedRows: {
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
},
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 {
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: {
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;
},
bodyContentStyle() {
2022-09-06 12:03:37 +00:00
return this.getVirtualScrollerProp('contentStyle');
2022-12-08 11:04:25 +00:00
},
ptmTBodyOptions() {
return {
context: {
scrollable: this.$parentInstance?.$parentInstance?.scrollable
}
};
},
expandedRowId() {
return UniqueComponentId();
},
nameAttributeSelector() {
return UniqueComponentId();
2022-09-06 12:03:37 +00:00
}
},
components: {
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>