提问人:Sharana Avali 提问时间:11/16/2023 最后编辑:TimurSharana Avali 更新时间:11/18/2023 访问量:62
如何在制表器中使特定单元格可编辑 [已关闭]
how to make particular cell editable in tabulator [closed]
问:
initializeTabulatortableBng() {
let classThis = this;
let bngTableData = classThis.tableDataWorm;
function decimalFormatter(cell) {
var value = cell.getValue();
if (value !== null && value !== undefined && !isNaN(value)) {
return parseFloat(value).toFixed(2);
}
return value;
}
this.bngTabulatorHeaders = [{
title: "Type",
field: "name",
headerHozAlign: "left",
width: 600,
headerSort: false,
hozAlign: "left",
editable: false
},
{
title: "Value",
headerHozAlign: "center",
width: 900,
columns: [{
title: "Min",
field: "minValue",
editor: false,
headerSort: false,
width: 300,
hozAlign: "right",
formatter: decimalFormatter,
headerHozAlign: "right",
editorParams: {
formatter: decimalFormatter
},
},
{
title: "Nom",
field: "nomValue",
editor: "input",
headerSort: false,
width: 300,
hozAlign: "right",
formatter: decimalFormatter,
headerHozAlign: "right",
editorParams: {
formatter: decimalFormatter
}
},
{
title: "Max",
field: "maxValue",
editor: false,
headerSort: false,
width: 300,
hozAlign: "right",
formatter: decimalFormatter,
headerHozAlign: "right",
editorParams: {
formatter: decimalFormatter
}
},
],
},
];
this.bngTabulatorTable = new Tabulator("#bngTabulatorTable", {
maxHeight: "100%",
maxwidth: "100%",
data: bngTableData,
layout: "fitColumns",
headerSort: false,
columns: this.bngTabulatorHeaders,
})
}
在这里,我想为 nom full 列启用编辑,我已经完成了它的工作,我想使可编辑单元格效率 [-] 行表示最小列第一个单元格,即 0.91 这里和伺服刚度(轴向)行 -min 列第 5 个单元格,即 0.00 表示效率 [-] 和伺服刚度(轴向)行应该是可编辑的 ''
答:
0赞
Timur
11/17/2023
#1
如果我理解正确,您希望根据 Type 值使某些单元格可编辑。如果是这种情况,您需要将 Min 和 Max 的编辑器类型更改为,并向这些列添加回调以确定它们是否应可编辑。请参阅下面的注释行:input
editable
// Function to check if the cell should be editable:
function editCheck(cell) {
const data = cell.getRow().getData()
return data.name === 'Efficiency [-]' || data.name === 'Servo Stiffness (axial)'
}
initializeTabulatortableBng() {
this.bngTabulatorHeaders = [
{
title: 'Type',
field: 'name',
headerHozAlign: 'left',
width: 600,
headerSort: false,
hozAlign: 'left',
editable: false
},
{
title: 'Value',
headerHozAlign: 'center',
width: 900,
columns: [
{
title: 'Min',
field: 'minValue',
editor: 'input', // <<<< Change editor to input
editable: editCheck, // <<<< Add editable callback
headerSort: false,
width: 300,
hozAlign: 'right',
formatter: decimalFormatter,
headerHozAlign: 'right',
editorParams: {
formatter: decimalFormatter
}
},
{
title: 'Nom',
field: 'nomValue',
editor: 'input',
headerSort: false,
width: 300,
hozAlign: 'right',
formatter: decimalFormatter,
headerHozAlign: 'right',
editorParams: {
formatter: decimalFormatter
}
},
{
title: 'Max',
field: 'maxValue',
editor: 'input', // <<<< Change editor to input
editable: editCheck, // <<<< Add editable callback
headerSort: false,
width: 300,
hozAlign: 'right',
formatter: decimalFormatter,
headerHozAlign: 'right',
editorParams: {
formatter: decimalFormatter
}
}
]
}
]
}
以下是其工作原理的基本示例:
const data = [
{ id: 1, name: 'Billy Bob', age: '12', gender: 'male', height: 1, col: 'red', dob: '', cheese: 1 },
{ id: 2, name: 'Mary May', age: '1', gender: 'female', height: 2, col: 'blue', dob: '14/05/1982', cheese: true },
{ id: 10, name: 'Margret Marmajuke', age: '16', gender: 'female', height: 5, col: 'yellow', dob: '31/01/1999' }
]
function editCheck(cell) {
const data = cell.getRow().getData()
const isEditable = data.name === 'Mary May' || data.name === 'Billy Bob'
if (!isEditable) {
cell.setValue('')
cell.getElement().style.backgroundColor = "#ccc"
}
return isEditable
}
const table = new Tabulator('#table', {
data: data,
columns: [
{ title: 'Name', field: 'name'},
{ title: 'Age', field: 'age', editor:'input', editable: editCheck },
{ title: 'Gender', field: 'gender' },
{ title: 'Height', field: 'height' },
{ title: 'Color', field: 'col' }
]
})
<link href="https://unpkg.com/[email protected]/dist/css/tabulator.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/js/tabulator.min.js"></script>
<div id="table"></div>
您也可以在此处阅读有关它的更多信息: https://tabulator.info/docs/5.5/edit#optional
评论
0赞
Sharana Avali
11/17/2023
谢谢它工作正常,但我想为不可编辑的单元格制作灰色 bg 颜色,并且不应该像这里一样显示值 16 对于 Margret Marmajuke 年龄
0赞
Timur
11/17/2023
您可以将其他逻辑添加到可编辑的回调函数中,以根据需要设置单元格的格式。我已经更新了我的基本示例,使不可编辑的单元格变灰。
评论