primevue-mirror/components/lib/treetable/FooterCell.vue

102 lines
3.1 KiB
Vue
Raw Normal View History

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('footerCell') }">
2022-09-14 11:26:01 +00:00
<component v-if="column.children && column.children.footer" :is="column.children.footer" :column="column" />
{{ columnProp('footer') }}
2022-09-06 12:03:37 +00:00
</td>
</template>
<script>
2023-05-11 08:11:49 +00:00
import BaseComponent from 'primevue/basecomponent';
2022-09-14 11:26:01 +00:00
import { DomHandler, ObjectUtils } from 'primevue/utils';
import { mergeProps } from 'vue';
2022-09-06 12:03:37 +00:00
export default {
name: 'FooterCell',
2023-07-04 06:29:36 +00:00
hostName: 'TreeTable',
2023-05-11 08:11:49 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
props: {
column: {
type: Object,
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: {}
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: {
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 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
},
getColumnProp() {
return this.column.props && this.column.props.pt ? this.column.props.pt : undefined;
},
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';
}
}
}
},
computed: {
containerClass() {
2023-06-05 07:34:19 +00:00
return [this.columnProp('footerClass'), this.columnProp('class'), this.cx('footerCell')];
2022-09-06 12:03:37 +00:00
},
containerStyle() {
let bodyStyle = this.columnProp('footerStyle');
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
}
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>