Heim > Fragen und Antworten > Hauptteil
P粉6593785772023-08-04 00:07:33
一种方法是使用editorParams中的itemFormatter选项来定义值列表的新元素节点,并返回包含列表值的元素的innerHTML:
editorParams: { values: ["a<b", "b<c", "c<d"], itemFormatter: (label, value, item, element) => { const listNode = document.createTextNode(value); element.appendChild(listNode); return element.innerHTML; } },
这是在name列上的一个示例:
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'
}
]
const table = new Tabulator('#example-table', {
data: data,
columns: [{
title: 'Name',
field: 'name',
editor: "list",
editorParams: {
values: ["a<b", "b<c", "c<d"],
itemFormatter: (label, value, item, element) => {
const listNode = document.createTextNode(value);
element.appendChild(listNode);
return element.innerHTML;
}
},
},
{
title: 'Age',
field: 'age'
},
{
title: 'Gender',
field: 'gender'
},
{
title: 'Height',
field: 'height'
},
{
title: 'Favourite Color',
field: 'col'
}
]
})
<link href="https://unpkg.com/tabulator-tables@5.5.1/dist/css/tabulator.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.5.1/dist/js/tabulator.min.js"></script>
<div id="example-table"></div>