1

我正在尝试根据 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'}
                ];

我没有运气使用格式化程序。另外,如果为真,如何显示图标,如果为假,则不显示。

任何帮助,将不胜感激。

4

2 回答 2

2

我通过使用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);
}

就那么简单 :)

于 2017-03-14T12:40:05.473 回答
0

很久以后,但尝试以下

{ 
    type: "control", 
    editButton: true
}

此外,正式文档中更好地描述了答案。

http://js-grid.com/docs/#control

于 2020-05-04T11:39:13.737 回答