Javascript 制表器:是否可以为每行添加带有计算值的自定义列?

Javascript 制表器:是否可以为每行添加带有计算值的自定义列?,javascript,vue.js,tabulator,Javascript,Vue.js,Tabulator,是否可以为每行添加具有计算值的自定义列?所以,如果列1的值为“3”,列2的值为“5”,那么我需要动态列3的和值为8 我正在使用Vue制表器。这是我的Table.vue组件 <template> <div v-if="tabledata" class="w-full p-3 border border-gray-200 shadow-xl rounded-lg mt-10"> <VueTabulator

是否可以为每行添加具有计算值的自定义列?所以,如果列1的值为“3”,列2的值为“5”,那么我需要动态列3的和值为8

我正在使用Vue制表器。这是我的Table.vue组件

<template>
    <div v-if="tabledata" class="w-full p-3 border border-gray-200 shadow-xl rounded-lg  mt-10">
        <VueTabulator id="usersData" v-model="tabledata" :options="options" />
    </div>
</template>
<script>
export default {
    data(){
        return{
            tabledata: [
                {
                    "name": "Hron",
                    "lvl2": 5,
                    "lvl3": 0,
                    "score": 5
                },
                {
                    "name": "Zhr",
                    "lvl2": 2,
                    "lvl3": 1,
                    "score": null
                },
                {
                    "name": "Mang",
                    "lvl2": 4,
                    "lvl3": 1,
                    "score": null
                }
            ],
            options: {
                layout:"fitColumns",
                columns: [
                    {title:"S#", formatter:"rownum", width:70, align:"center", responsive:3},
                    {title:"Name", field:"name", minWidth:150},
                    {title:"Lvl 2", field:"lvl2", sorter:"number", align:"center", formatter:"money", formatterParams:{precision:false}, bottomCalc:"sum", minWidth:80},
                    {title:"Lvl 3", field:"lvl3", sorter:"number", align:"center", formatter:"money", formatterParams:{precision:false}, bottomCalc:"sum", minWidth:80},
                    {title:"Score", field:"score", sorter:"number", align:"center", formatterParams:{precision:true}, bottomCalc:"avg"}
                ]
            }
        }
    }
}
</script>
我一直在查看文档,但没有找到任何东西

谢谢

您将希望使用突变子来实现这一点

如果我们从包含两列值的样本数据开始

var数据=[
{col1:27,col2:55}
];
然后定义一个自定义的mutator函数来计算这两行的总和

var customMutator=函数(值、数据、类型、参数、组件){
//值-单元格的原始值
//数据-行的数据
//类型-发生突变的类型(数据编辑)
//params-列定义中的mutatorParams对象
//组件-当“type”参数为“edit”时,它包含已编辑单元格的单元格组件,否则它是该列的列组件
return data.col1+data.col2;//返回其他两列的总和。
}
然后在列定义中,我们添加第三列,其中包含一个虚构的字段名称,并在mutator属性上设置mutator函数:

列:[
{标题:“第1列”,字段:“col1”},
{标题:“第2列”,字段:“col2”},
{title:“Sum Column”,字段:“sumCol”,mutator:customMutator},//使Column成为其他两列的和
]

详细信息可在

中找到,非常感谢。
[
  {
    "name": "Hron",
    "lvl2": 5,
    "lvl3": 0,
    "score": 5
  },
  {
    "name": "Zhr",
    "lvl2": 2,
    "lvl3": 1,
    "score": 3
  },
  {
    "name": "Mang",
    "lvl2": 4,
    "lvl3": 1,
    "score": 5
  }
]