2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-09-14 11:26:01 +00:00
|
|
|
<tfoot v-if="hasFooter" class="p-datatable-tfoot" role="rowgroup">
|
2022-09-06 12:03:37 +00:00
|
|
|
<tr v-if="!columnGroup" role="row">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(col, i) of columns" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || i">
|
|
|
|
<DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
<template v-else>
|
2022-09-14 11:26:01 +00:00
|
|
|
<tr v-for="(row, i) of getFooterRows()" :key="i" role="row">
|
|
|
|
<template v-for="(col, j) of getFooterColumns(row)" :key="columnProp(col, 'columnKey') || columnProp(col, 'field') || j">
|
|
|
|
<DTFooterCell v-if="!columnProp(col, 'hidden')" :column="col" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
</tfoot>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-09-14 11:26:01 +00:00
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
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',
|
|
|
|
props: {
|
|
|
|
columnGroup: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
columns: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2022-09-14 11:26:01 +00:00
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
columnProp(col, prop) {
|
|
|
|
return ObjectUtils.getVNodeProp(col, prop);
|
|
|
|
},
|
|
|
|
getFooterRows() {
|
|
|
|
let rows = [];
|
|
|
|
|
|
|
|
let columnGroup = this.columnGroup;
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
if (columnGroup.children && columnGroup.children.default) {
|
|
|
|
for (let child of columnGroup.children.default()) {
|
|
|
|
if (child.type.name === 'Row') {
|
|
|
|
rows.push(child);
|
2022-09-14 11:26:01 +00:00
|
|
|
} else if (child.children && child.children instanceof Array) {
|
2022-09-06 12:03:37 +00:00
|
|
|
rows = child.children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
getFooterColumns(row) {
|
2022-09-06 12:03:37 +00:00
|
|
|
let cols = [];
|
|
|
|
|
|
|
|
if (row.children && row.children.default) {
|
2022-09-14 11:26:01 +00:00
|
|
|
row.children.default().forEach((child) => {
|
|
|
|
if (child.children && child.children instanceof Array) cols = [...cols, ...child.children];
|
|
|
|
else if (child.type.name === 'Column') cols.push(child);
|
2022-09-06 12:03:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return cols;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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>
|