2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-11-09 15:02:09 +00:00
|
|
|
<td :style="containerStyle" :class="containerClass" role="cell" :colspan="columnProp('colspan')" :rowspan="columnProp('rowspan')" v-bind="{ ...getColumnPT('root'), ...getColumnPT('footerCell') }" :data-p-frozen-column="columnProp('frozen')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<component v-if="column.children && column.children.footer" :is="column.children.footer" :column="column" />
|
2024-05-25 15:09:39 +00:00
|
|
|
<span v-if="columnProp('footer')" :class="cx('columnFooter')" v-bind="getColumnPT('columnFooter')">{{ columnProp('footer') }}</span>
|
2022-09-06 12:03:37 +00:00
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-06-11 12:21:12 +00:00
|
|
|
import BaseComponent from '@primevue/core/basecomponent';
|
2024-06-26 07:46:26 +00:00
|
|
|
import { getVNodeProp } from '@primevue/core/utils';
|
|
|
|
import { getNextElementSibling, getOuterWidth, getPreviousElementSibling } from '@primeuix/utils/dom';
|
2023-07-13 11:12:07 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'FooterCell',
|
2023-06-08 11:26:48 +00:00
|
|
|
hostName: 'DataTable',
|
2023-05-08 14:08:06 +00:00
|
|
|
extends: BaseComponent,
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
column: {
|
2023-04-13 18:05:42 +00:00
|
|
|
type: Object,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
2023-06-02 11:10:18 +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) {
|
2024-06-26 07:46:26 +00:00
|
|
|
return getVNodeProp(this.column, prop);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-06-02 11:10:18 +00:00
|
|
|
getColumnPT(key) {
|
|
|
|
const columnMetaData = {
|
2023-05-09 14:57:31 +00:00
|
|
|
props: this.column.props,
|
|
|
|
parent: {
|
2023-12-05 11:06:32 +00:00
|
|
|
instance: this,
|
2023-05-09 14:57:31 +00:00
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-02 11:10:18 +00:00
|
|
|
},
|
|
|
|
context: {
|
2023-07-19 12:05:06 +00:00
|
|
|
index: this.index,
|
|
|
|
size: this.$parentInstance?.$parentInstance?.size,
|
|
|
|
showGridlines: this.$parentInstance?.$parentInstance?.showGridlines || false
|
2023-05-09 14:57:31 +00:00
|
|
|
}
|
2023-06-02 11:10:18 +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-05-09 14:57:31 +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');
|
2024-10-29 09:38:37 +00:00
|
|
|
let isRTL = this.$parentInstance.$parentInstance.isRTL;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (align === 'right') {
|
2024-10-29 09:38:37 +00:00
|
|
|
let pos = 0;
|
2024-06-26 07:46:26 +00:00
|
|
|
let next = 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) {
|
2024-10-29 09:38:37 +00:00
|
|
|
pos = getOuterWidth(next) + parseFloat(next.style.right || 0);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2024-10-29 09:38:37 +00:00
|
|
|
if (isRTL) {
|
|
|
|
this.styleObject.left = pos + 'px';
|
|
|
|
} else {
|
|
|
|
this.styleObject.right = pos + 'px';
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
2024-10-29 09:38:37 +00:00
|
|
|
let pos = 0;
|
2024-06-26 07:46:26 +00:00
|
|
|
let prev = 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) {
|
2024-10-29 09:38:37 +00:00
|
|
|
pos = getOuterWidth(prev) + parseFloat(prev.style.left || 0);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2024-10-29 09:38:37 +00:00
|
|
|
if (isRTL) {
|
|
|
|
this.styleObject.right = pos + 'px';
|
|
|
|
} else {
|
|
|
|
this.styleObject.left = pos + 'px';
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2023-06-08 11:26:48 +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>
|