如何在Grid.js中使用 HTML 内容填充单元格?
问问题
1116 次
3 回答
1
我正在通过浏览器使用 gridjs CDN 实现,我可以通过 gridjs 命名空间访问 html 函数来使用格式化程序,如下所示
{
name: "Action",
formatter: (cell) => {
return gridjs.html(`<a href="">update</a>`)
// return `Update button`
}
}
于 2020-08-24T03:53:37.570 回答
1
对我来说,我将脚本类型“text/javascript”设置为“模块”。然后我可以像这样使用“导入”=>
<script type="module">
import {
Grid,
html
} from "/Scripts/gridjs.production.es.min.js";
//then use html with formatter
{
name: "Actions",
formatter: (cell) => {
return html(`<a data-id=${cell} href="#"><span class="glyphicon glyphicon-pencil"></span>Edit</a>`)
}
}
</script>
于 2020-09-23T08:37:25.913 回答
0
先导入html
函数:
import { Grid, html } from "gridjs";
然后在formatter
函数中使用它或直接在data
:
const grid = new Grid({
columns: [
{
name: 'Name',
formatter: (cell) => html(`<b>${cell}</b>`)
},
'Email',
{
name: 'Actions',
formatter: (_, row) => html(`<a href='mailto:${row.cells[1].data}'>Email</a>`)
},
],
data: Array(5).fill().map(x => [
faker.name.findName(),
faker.internet.email(),
null
])
});
于 2020-06-07T11:52:29.647 回答