我试图根据JSGrid中的值是true还是false来添加图标(锁定)。
我有一个名为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'}
];
我没有运气使用格式化程序。另外,如果为真,我怎么能显示一个图标,如果是假的话,我怎么能显示。
任何帮助都将不胜感激。
答案 0 :(得分:1)
我使用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);
}
},
简单如下:)
答案 1 :(得分:0)
稍后,请尝试以下操作
{
type: "control",
editButton: true
}
答案也可以在正式文档中得到更好的描述。