2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-07-19 12:05:06 +00:00
|
|
|
<tfoot v-if="hasFooter" :class="cx('tfoot')" :style="sx('tfoot')" role="rowgroup" v-bind="columnGroup ? { ...ptm('tfoot', ptmTFootOptions), ...getColumnGroupPT('root') } : ptm('tfoot', ptmTFootOptions)" data-pc-section="tfoot">
|
2023-05-08 14:08:06 +00:00
|
|
|
<tr v-if="!columnGroup" role="row" v-bind="ptm('footerRow')">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i">
|
2023-05-08 14:08:06 +00:00
|
|
|
<DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" :pt="pt" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
<template v-else>
|
2023-06-02 11:10:18 +00:00
|
|
|
<tr v-for="(row, i) of getFooterRows()" :key="i" role="row" v-bind="{ ...ptm('footerRow'), ...getRowPT(row, 'root', i) }">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(col, j) of getFooterColumns(row)" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || j">
|
2023-06-02 11:10:18 +00:00
|
|
|
<DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" :index="i" :pt="pt" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
</tfoot>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-08 14:08:06 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2023-12-21 23:41:41 +00:00
|
|
|
import { HelperSet, ObjectUtils } from 'primevue/utils';
|
2023-07-13 11:12:07 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2022-12-08 11:04:25 +00:00
|
|
|
import FooterCell from './FooterCell.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TableFooter',
|
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: {
|
|
|
|
columnGroup: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
columns: {
|
2023-04-13 18:05:42 +00:00
|
|
|
type: Object,
|
2022-09-06 12:03:37 +00:00
|
|
|
default: null
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-12-21 23:41:41 +00:00
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
$rows: this.d_footerRows,
|
|
|
|
$columns: this.d_footerColumns
|
|
|
|
};
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
d_footerRows: new HelperSet({ type: 'Row' }),
|
|
|
|
d_footerColumns: new HelperSet({ type: 'Column' })
|
|
|
|
};
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
this.d_footerRows.clear();
|
|
|
|
this.d_footerColumns.clear();
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
|
|
|
columnProp(col, prop) {
|
|
|
|
return ObjectUtils.getVNodeProp(col, prop);
|
|
|
|
},
|
2023-06-02 11:10:18 +00:00
|
|
|
getColumnGroupPT(key) {
|
|
|
|
const columnGroupMetaData = {
|
2023-05-10 11:39:25 +00:00
|
|
|
props: this.getColumnGroupProps(),
|
|
|
|
parent: {
|
2023-12-05 11:06:32 +00:00
|
|
|
instance: this,
|
2023-05-10 11:39:25 +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
|
|
|
type: 'footer',
|
|
|
|
scrollable: this.ptmTFootOptions.context.scrollable
|
2023-05-10 11:39:25 +00:00
|
|
|
}
|
2023-06-02 11:10:18 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 11:12:07 +00:00
|
|
|
return mergeProps(this.ptm(`columnGroup.${key}`, { columnGroup: columnGroupMetaData }), this.ptm(`columnGroup.${key}`, columnGroupMetaData), this.ptmo(this.getColumnGroupProps(), key, columnGroupMetaData));
|
2023-05-10 11:39:25 +00:00
|
|
|
},
|
|
|
|
getColumnGroupProps() {
|
|
|
|
return this.columnGroup && this.columnGroup.props && this.columnGroup.props.pt ? this.columnGroup.props.pt : undefined; //@todo
|
|
|
|
},
|
2023-06-02 11:10:18 +00:00
|
|
|
getRowPT(row, key, index) {
|
|
|
|
const rowMetaData = {
|
2023-05-10 11:39:25 +00:00
|
|
|
props: row.props,
|
|
|
|
parent: {
|
2023-12-05 11:06:32 +00:00
|
|
|
instance: this,
|
2023-05-10 11:39:25 +00:00
|
|
|
props: this.$props,
|
|
|
|
state: this.$data
|
2023-06-02 11:10:18 +00:00
|
|
|
},
|
|
|
|
context: {
|
|
|
|
index
|
2023-05-10 11:39:25 +00:00
|
|
|
}
|
2023-06-02 11:10:18 +00:00
|
|
|
};
|
|
|
|
|
2023-07-13 11:12:07 +00:00
|
|
|
return mergeProps(this.ptm(`row.${key}`, { row: rowMetaData }), this.ptm(`row.${key}`, rowMetaData), this.ptmo(this.getRowProp(row), key, rowMetaData));
|
2023-05-10 11:39:25 +00:00
|
|
|
},
|
|
|
|
getRowProp(row) {
|
|
|
|
return row.props && row.props.pt ? row.props.pt : undefined; //@todo
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
getFooterRows() {
|
2023-12-21 23:41:41 +00:00
|
|
|
return this.d_footerRows?.get(this.columnGroup, this.columnGroup.children);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
getFooterColumns(row) {
|
2023-12-21 23:41:41 +00:00
|
|
|
return this.d_footerColumns?.get(row, row.children);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
hasFooter() {
|
|
|
|
let hasFooter = false;
|
|
|
|
|
|
|
|
if (this.columnGroup) {
|
|
|
|
hasFooter = true;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (this.columns) {
|
2022-09-06 12:03:37 +00:00
|
|
|
for (let col of this.columns) {
|
|
|
|
if (this.columnProp(col, 'footer') || (col.children && col.children.footer)) {
|
|
|
|
hasFooter = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasFooter;
|
2023-07-19 12:05:06 +00:00
|
|
|
},
|
|
|
|
ptmTFootOptions() {
|
|
|
|
return {
|
|
|
|
context: {
|
|
|
|
scrollable: this.$parentInstance?.$parentInstance?.scrollable
|
|
|
|
}
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
DTFooterCell: FooterCell
|
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>
|