comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
73 lines (72 loc) • 2.23 kB
JavaScript
import { defineComponent, inject, ref, h } from "vue";
import { TABLE_PROVIDE } from "../type.mjs";
import TableColgroup from "../components/table-colgroup.mjs";
const TableFooter = defineComponent({
name: "TableFooter",
setup() {
var _a;
const { props, columns, getFixedIndex, getCellClass } = inject(TABLE_PROVIDE);
const defaultSummaryMethod = ({ columns: columns2, datas }) => {
const sum = columns2.map((col, idx) => {
if (idx === 0) return props.sumText;
return datas.reduce((result, row) => {
if (isNaN(result + Number(row[col.prop]))) {
return "";
} else {
return result + Number(row[col.prop]);
}
}, 0);
});
return sum;
};
const params = ref({
columns: columns.value.map((v) => v.props),
datas: props.data
});
const footerCols = ((_a = props.summaryMethod) == null ? void 0 : _a.call(props, params.value)) || defaultSummaryMethod(params.value);
return () => {
return h(
"div",
{
class: "cu-table__footer"
},
h(
"table",
{
cellspacing: 0,
cellpadding: 0
},
[
h(TableColgroup),
h(
"tfoot",
h("tr", { class: "cu-table__row" }, [
columns.value.map((col, colIdx) => {
return h(
"th",
{
key: col.uid,
class: [
"cu-table__th",
col.fixed ? "fixed-" + col.fixed : void 0,
{ "fixed-shadow-left": getFixedIndex.value.left == colIdx },
{ "fixed-shadow-right": getFixedIndex.value.right == colIdx }
],
style: col.style,
rowspan: 1,
colspan: 1
},
h("div", { class: ["cu-table__cell", ...getCellClass(col)] }, footerCols[colIdx])
);
})
])
)
]
)
);
};
}
});
export {
TableFooter as default
};