2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-06-05 08:36:46 +00:00
|
|
|
<td :style="containerStyle" :class="containerClass" role="cell" v-bind="{ ...getColumnPT('root'), ...getColumnPT('bodyCell') }">
|
|
|
|
<button v-if="columnProp('expander')" v-ripple type="button" :class="cx('rowToggler')" @click="toggle" :style="togglerStyle" tabindex="-1" v-bind="getColumnPT('rowToggler')">
|
2023-06-05 07:34:19 +00:00
|
|
|
<component v-if="templates['togglericon']" :is="templates['togglericon']" :node="node" :expanded="expanded" :class="cx('rowTogglerIcon')" />
|
2023-06-05 08:36:46 +00:00
|
|
|
<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')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
2023-06-05 08:36:46 +00:00
|
|
|
<div v-if="checkboxSelectionMode && columnProp('expander')" :class="cx('checkboxWrapper')" @click="toggleCheckbox" v-bind="getColumnPT('checkboxWrapper')">
|
|
|
|
<div :class="cx('hiddenInputWrapper')" :style="sx('hiddenAccessible', isUnstyled)" v-bind="getColumnPT('hiddenInputWrapper')" :data-p-hidden-accessible="true">
|
|
|
|
<input type="checkbox" @focus="onCheckboxFocus" @blur="onCheckboxBlur" tabindex="-1" v-bind="getColumnPT('hiddenInput')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2023-06-05 08:36:46 +00:00
|
|
|
<div ref="checkboxEl" :class="cx('checkbox')" v-bind="getColumnCheckboxPT('checkbox')">
|
2023-06-05 07:34:19 +00:00
|
|
|
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="checked" :partialChecked="partialChecked" :class="cx('checkboxicon')" />
|
2023-06-05 08:36:46 +00:00
|
|
|
<component v-else :is="checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :class="cx('checkboxicon')" v-bind="getColumnCheckboxPT('checkboxIcon')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
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 08:36:46 +00:00
|
|
|
<span v-bind="getColumnPT('cellContent')">{{ 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';
|
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';
|
2022-09-14 11:26:01 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ObjectUtils } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'BodyCell',
|
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
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
styleObject: {},
|
|
|
|
checkboxFocused: false
|
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: {
|
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-05 08:36:46 +00:00
|
|
|
},
|
|
|
|
context: {
|
|
|
|
index: this.index
|
2023-05-11 08:11:49 +00:00
|
|
|
}
|
2023-06-05 08:36:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return { ...this.ptm(`column.${key}`, { column: columnMetaData }), ...this.ptmo(this.getColumnProp(), key, columnMetaData) };
|
|
|
|
},
|
|
|
|
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-05-11 08:11:49 +00:00
|
|
|
return this.ptmo(this.getColumnProp(), key, {
|
|
|
|
props: this.column.props,
|
|
|
|
parent: {
|
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
|
|
|
},
|
|
|
|
context: {
|
|
|
|
checked: this.checked,
|
|
|
|
focused: this.checkboxFocused,
|
|
|
|
partialChecked: this.partialChecked
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
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;
|
|
|
|
let next = this.$el.nextElementSibling;
|
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;
|
|
|
|
let prev = this.$el.previousElementSibling;
|
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');
|
|
|
|
},
|
|
|
|
onCheckboxFocus() {
|
|
|
|
this.checkboxFocused = true;
|
|
|
|
},
|
|
|
|
onCheckboxBlur() {
|
|
|
|
this.checkboxFocused = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
ChevronRightIcon: ChevronRightIcon,
|
|
|
|
ChevronDownIcon: ChevronDownIcon,
|
|
|
|
CheckIcon: CheckIcon,
|
|
|
|
MinusIcon: MinusIcon
|
|
|
|
},
|
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>
|