如何使用检查和X渲染jQuery DataTable Boolean列?

发布于 2025-01-18 14:01:00 字数 617 浏览 2 评论 0原文

我想在两个布尔列上使用以下 columnDef 来显示 true 的检查和 false 的 x 的检查。但是,列上没有显示任何内容:

{
    targets: [5, 6],
    render: function (data, type, row) {
        return (data === true) ? '<span class="glyphicon glyphicon-ok txt-green"></span>' : '<span class="glyphicon glyphicon-remove txt-red"></span>';
    }
}

以下内容确实有效,但很难看到正确值的复选标记。我更喜欢 glyphicon 选项:

{
    targets: [5, 6],
    render: function (data, type, full, meta) {
        return data ? '<input type="checkbox" disabled checked/>' : '<input type="checkbox" disabled />';
    }
}

I would like to use the following columnDef on two boolean columns to display a check for true and x for false. However, nothing gets displayed on the columns:

{
    targets: [5, 6],
    render: function (data, type, row) {
        return (data === true) ? '<span class="glyphicon glyphicon-ok txt-green"></span>' : '<span class="glyphicon glyphicon-remove txt-red"></span>';
    }
}

The following does work, but it is difficult to see the checkmarks for values that are true. I prefer the glyphicon option:

{
    targets: [5, 6],
    render: function (data, type, full, meta) {
        return data ? '<input type="checkbox" disabled checked/>' : '<input type="checkbox" disabled />';
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不吻晚风 2025-01-25 14:01:00

字形示例不起作用,因为它们不再在Bootstrap 4及更高版本中得到支持。

以下是我使用fontawesome图标的解决方案:

{
    targets: [5, 6],
    render: function (data) {
        return data ? '<span class="fa fa-solid fa-check" style="color: green"></span>' : '<span class="fa fa-solid fa-times" style="color: red"></span>';
    }
}

The glyphicons example was not working because they are no longer supported in Bootstrap 4 and above.

The following is my solution using fontawesome icons:

{
    targets: [5, 6],
    render: function (data) {
        return data ? '<span class="fa fa-solid fa-check" style="color: green"></span>' : '<span class="fa fa-solid fa-times" style="color: red"></span>';
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文