javascript - JSGrid 根据 true 或 false 值添加图标而不是文本

标签 javascript grid jsgrid

我正在尝试根据 JSGrid 中的值是真还是假来添加图标(锁)。

我有一个名为 SoftLock 的变量,如果这是真的,我想在网格上插入一个锁图标。

我有以下字段,但不确定如何继续:

var fields = [
                        { name: 'ID', type: 'text', visible: false },
//THIS FIELD BELOW
                        { name: 'SoftLock', type: 'text', title: 'Locked', formatter : function () {return "<span class='fa fa-lock'><i class='fa fa-lock' aria-hidden='true'></i></span>"} },
//THIS FIELD ABOVE
                        { name: 'Status', type: 'select', items: MatterStatusEnum.List, valueField: 'Id', textField: 'Name', width: 70, title: 'Account Status' },
                        { name: 'AttorneyRef', type: 'text', title: 'Reference' },
                        { name: 'Investors', type: 'text', title: 'Investor/s' },
                        { name: 'AccountNumber', type: 'text', width: 70, title: 'Account Number' },
                        { name: 'IntermediaryName', type: 'text', title: 'Intermediary Name' },
                        { name: 'CreatedBy', type: 'text', title: 'Captured By' },
                        { name: 'RequestedDate', type: 'date', title: 'Requested Date'}
                ];

我用过格式化程序,但没有成功。另外,如果为 true,我如何显示图标,如果为 false,则什么都不显示。

如有任何帮助,我们将不胜感激。

最佳答案

我使用 itemTemplate 解决了这个问题,如下所示:

{ 
name: 'SoftLock', type: 'text', title: 'Locked', width: 30, 
itemTemplate : function (value, item) {
    var iconClass = "";
    if (value == true) {
        iconClass = "fa fa-lock"; //this is my class with an icon
    } 
    return $("<span>").attr("class", iconClass);
}

就这么简单:)

关于javascript - JSGrid 根据 true 或 false 值添加图标而不是文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42783026/

相关文章:

css - 如何将 css 类添加到 jsGrid 的最后一行

javascript - JSGrid 以编程方式选择第一行

javascript - 如何设置 jQuery 断点?

javascript - Protractor 循环数组并打开 url

css - gxt 网格 : span column header over multiple columns

vb.net - 如何在 c1flexgrid 中通过代码设置 DataField 属性

grid - Kendo UI Grid 内联编辑发布的数据为空

javascript - jsGrid 中的自动调整列大小

javascript - 如何向 Vue.js Okta 身份验证应用程序添加注册

JavaScript 回调函数 ..ish 问题