2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-11-09 15:02:09 +00:00
|
|
|
<td :style="containerStyle" :class="containerClass" role="cell" v-bind="{ ...getColumnPT('root'), ...getColumnPT('bodyCell') }" :data-p-frozen-column="columnProp('frozen')">
|
2023-08-28 09:20:55 +00:00
|
|
|
<button v-if="columnProp('expander')" v-ripple type="button" :class="cx('rowToggler')" @click="toggle" :style="togglerStyle" tabindex="-1" v-bind="getColumnPT('rowToggler')" data-pc-group-section="rowactionbutton">
|
2023-11-28 08:46:39 +00:00
|
|
|
<template v-if="node.loading && loadingMode === 'icon'">
|
|
|
|
<component v-if="templates['nodetogglericon']" :is="templates['nodetogglericon']" :class="cx('nodetogglericon')" />
|
|
|
|
<SpinnerIcon v-else spin :class="cx('nodetogglericon')" v-bind="ptm('nodetogglericon')" />
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<component v-if="column.children && column.children.rowtogglericon" :is="column.children && column.children.rowtogglericon" :node="node" :expanded="expanded" :class="cx('rowTogglerIcon')" />
|
|
|
|
<component v-else-if="expanded" :is="node.expandedIcon ? 'span' : 'ChevronDownIcon'" :class="cx('rowTogglerIcon')" v-bind="getColumnPT('rowTogglerIcon')" />
|
|
|
|
<component v-else :is="node.collapsedIcon ? 'span' : 'ChevronRightIcon'" :class="cx('rowTogglerIcon')" v-bind="getColumnPT('rowTogglerIcon')" />
|
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
2024-01-14 13:38:51 +00:00
|
|
|
<Checkbox
|
|
|
|
v-if="checkboxSelectionMode && columnProp('expander')"
|
|
|
|
:modelValue="checked"
|
|
|
|
:binary="true"
|
|
|
|
:class="cx('rowCheckbox')"
|
|
|
|
@change="toggleCheckbox"
|
2024-01-18 12:16:58 +00:00
|
|
|
:tabindex="-1"
|
2024-03-27 08:40:37 +00:00
|
|
|
:indeterminate="partialChecked"
|
2024-01-14 14:09:03 +00:00
|
|
|
:unstyled="unstyled"
|
2024-01-14 13:38:51 +00:00
|
|
|
:pt="getColumnCheckboxPT('rowCheckbox')"
|
|
|
|
:data-p-partialchecked="partialChecked"
|
|
|
|
>
|
|
|
|
<template #icon="slotProps">
|
|
|
|
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="slotProps.checked" :partialChecked="partialChecked" :class="slotProps.class" />
|
|
|
|
</template>
|
|
|
|
</Checkbox>
|
2022-09-14 11:26:01 +00:00
|
|
|
<component v-if="column.children && column.children.body" :is="column.children.body" :node="node" :column="column" />
|
2023-04-13 08:53:28 +00:00
|
|
|
<template v-else>
|
2023-06-05 13:26:08 +00:00
|
|
|
<span v-bind="getColumnPT('bodyCellContent')">{{ resolveFieldData(node.data, columnProp('field')) }}</span>
|
2023-04-13 08:53:28 +00:00
|
|
|
</template>
|
2022-09-06 12:03:37 +00:00
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-11 08:11:49 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2024-01-14 13:38:51 +00:00
|
|
|
import Checkbox from 'primevue/checkbox';
|
2023-04-18 12:53:43 +00:00
|
|
|
import CheckIcon from 'primevue/icons/check';
|
|
|
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
|
|
|
import ChevronRightIcon from 'primevue/icons/chevronright';
|
|
|
|
import MinusIcon from 'primevue/icons/minus';
|
2023-11-28 08:46:39 +00:00
|
|
|
import SpinnerIcon from 'primevue/icons/spinner';
|
2023-12-05 11:06:32 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ObjectUtils } from 'primevue/utils';
|
2023-07-13 11:12:07 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'BodyCell',
|
2023-07-04 06:29:36 +00:00
|
|
|
hostName: 'TreeTable',
|
2023-05-11 08:11:49 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-14 11:26:01 +00:00
|
|
|
emits: ['node-toggle', 'checkbox-toggle'],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
node: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
column: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
level: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
indentation: {
|
|
|
|
type: Number,
|
|
|
|
default: 1
|
|
|
|
},
|
|
|
|
leaf: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
expanded: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
selectionMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
checked: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
partialChecked: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2023-04-13 08:53:28 +00:00
|
|
|
},
|
|
|
|
templates: {
|
2023-04-13 18:05:42 +00:00
|
|
|
type: Object,
|
2023-04-13 08:53:28 +00:00
|
|
|
default: null
|
2023-06-05 08:36:46 +00:00
|
|
|
},
|
|
|
|
index: {
|
|
|
|
type: Number,
|
|
|
|
default: null
|
2023-11-28 08:46:39 +00:00
|
|
|
},
|
|
|
|
loadingMode: {
|
|
|
|
type: String,
|
|
|
|
default: 'mask'
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-01-14 13:38:51 +00:00
|
|
|
styleObject: {}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.columnProp('frozen')) {
|
|
|
|
this.updateStickyPosition();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
if (this.columnProp('frozen')) {
|
|
|
|
this.updateStickyPosition();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggle() {
|
|
|
|
this.$emit('node-toggle', this.node);
|
|
|
|
},
|
|
|
|
columnProp(prop) {
|
|
|
|
return ObjectUtils.getVNodeProp(this.column, prop);
|
|
|
|
},
|
2023-06-05 08:36:46 +00:00
|
|
|
getColumnPT(key) {
|
|
|
|
const columnMetaData = {
|
2023-05-11 08:11:49 +00:00
|
|
|
props: this.column.props,
|
|
|
|
parent: {
|
2023-12-05 11:06:32 +00:00
|
|
|
instance: this,
|
2023-05-11 08:11:49 +00:00
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-05 08:36:46 +00:00
|
|
|
},
|
|
|
|
context: {
|
2023-07-17 09:23:09 +00:00
|
|
|
index: this.index,
|
|
|
|
selectable: this.$parentInstance.rowHover || this.$parentInstance.rowSelectionMode,
|
|
|
|
selected: this.$parent.selected,
|
2023-07-19 12:06:27 +00:00
|
|
|
frozen: this.columnProp('frozen'),
|
|
|
|
scrollable: this.$parentInstance.scrollable,
|
|
|
|
scrollDirection: this.$parentInstance.scrollDirection,
|
|
|
|
showGridlines: this.$parentInstance.showGridlines,
|
|
|
|
size: this.$parentInstance?.size
|
2023-05-11 08:11:49 +00:00
|
|
|
}
|
2023-06-05 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 11:12:07 +00:00
|
|
|
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(), key, columnMetaData));
|
2023-06-05 08:36:46 +00:00
|
|
|
},
|
|
|
|
getColumnProp() {
|
|
|
|
return this.column.props && this.column.props.pt ? this.column.props.pt : undefined; //@todo
|
2023-05-11 08:11:49 +00:00
|
|
|
},
|
2023-06-05 08:36:46 +00:00
|
|
|
getColumnCheckboxPT(key) {
|
2023-07-19 12:06:27 +00:00
|
|
|
const columnMetaData = {
|
2023-05-11 08:11:49 +00:00
|
|
|
props: this.column.props,
|
|
|
|
parent: {
|
2023-12-05 11:06:32 +00:00
|
|
|
instance: this,
|
2023-05-11 08:11:49 +00:00
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
|
|
|
},
|
|
|
|
context: {
|
|
|
|
checked: this.checked,
|
|
|
|
partialChecked: this.partialChecked
|
|
|
|
}
|
2023-07-19 12:06:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(), key, columnMetaData));
|
2023-05-11 08:11:49 +00:00
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
updateStickyPosition() {
|
|
|
|
if (this.columnProp('frozen')) {
|
|
|
|
let align = this.columnProp('alignFrozen');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (align === 'right') {
|
|
|
|
let right = 0;
|
2023-11-09 15:02:09 +00:00
|
|
|
let next = DomHandler.getNextElementSibling(this.$el, '[data-p-frozen-column="true"]');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (next) {
|
|
|
|
right = DomHandler.getOuterWidth(next) + parseFloat(next.style.right || 0);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.styleObject.right = right + 'px';
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2022-09-06 12:03:37 +00:00
|
|
|
let left = 0;
|
2023-11-09 15:02:09 +00:00
|
|
|
let prev = DomHandler.getPreviousElementSibling(this.$el, '[data-p-frozen-column="true"]');
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (prev) {
|
|
|
|
left = DomHandler.getOuterWidth(prev) + parseFloat(prev.style.left || 0);
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.styleObject.left = left + 'px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolveFieldData(rowData, field) {
|
|
|
|
return ObjectUtils.resolveFieldData(rowData, field);
|
|
|
|
},
|
|
|
|
toggleCheckbox() {
|
|
|
|
this.$emit('checkbox-toggle');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2023-06-05 07:34:19 +00:00
|
|
|
return [this.columnProp('bodyClass'), this.columnProp('class'), this.cx('bodyCell')];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
containerStyle() {
|
|
|
|
let bodyStyle = this.columnProp('bodyStyle');
|
|
|
|
let columnStyle = this.columnProp('style');
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.columnProp('frozen') ? [columnStyle, bodyStyle, this.styleObject] : [columnStyle, bodyStyle];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
togglerStyle() {
|
|
|
|
return {
|
|
|
|
marginLeft: this.level * this.indentation + 'rem',
|
|
|
|
visibility: this.leaf ? 'hidden' : 'visible'
|
|
|
|
};
|
|
|
|
},
|
|
|
|
checkboxSelectionMode() {
|
|
|
|
return this.selectionMode === 'checkbox';
|
|
|
|
}
|
|
|
|
},
|
2023-04-13 08:53:28 +00:00
|
|
|
components: {
|
2024-01-14 13:38:51 +00:00
|
|
|
Checkbox,
|
|
|
|
ChevronRightIcon,
|
|
|
|
ChevronDownIcon,
|
|
|
|
CheckIcon,
|
|
|
|
MinusIcon,
|
|
|
|
SpinnerIcon
|
2023-04-13 08:53:28 +00:00
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
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>
|