如何在Grid.js中使用HTML内容填充单元格
发布于 2020-06-07 11:52:29
首先导入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-09-23 08:37:25
对我来说,我将脚本类型"text/javascript“设置为"module”。然后我就可以像这个=>一样使用“导入”
<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-08-24 03:53:37
我通过浏览器使用gridjs CDN实现,我可以通过gridjs命名空间访问html函数,如下所示
{
name: "Action",
formatter: (cell) => {
return gridjs.html(`<a href="">update</a>`)
// return `Update button`
}
}https://stackoverflow.com/questions/62244896
复制相似问题