primevue-mirror/packages/primevue/src/datatable/FooterCell.vue

115 lines
4.0 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<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" />
<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';
import { getVNodeProp } from '@primevue/core/utils';
import { getNextElementSibling, getOuterWidth, getPreviousElementSibling } from '@primeuix/utils/dom';
import { mergeProps } from 'vue';
2022-09-06 12:03:37 +00:00
export default {
name: 'FooterCell',
hostName: 'DataTable',
2023-05-08 14:08:06 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
props: {
column: {
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) {
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 = {
props: this.column.props,
parent: {
instance: this,
props: this.$props,
state: this.$data
2023-06-02 11:10:18 +00:00
},
context: {
index: this.index,
size: this.$parentInstance?.$parentInstance?.size,
showGridlines: this.$parentInstance?.$parentInstance?.showGridlines || false
}
2023-06-02 11:10:18 +00:00
};
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(), key, columnMetaData));
},
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;
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;
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() {
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>