转到 aurelia slickgrid 示例link 并点击示例源代码链接
打开的时候有个方法叫defineGrids
/* Define grid Options and Columns */
defineGrids() {
this.columnDefinitions1 = [
...,
...,
...,
...,
...,
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: myCustomCheckmarkFormatter, type: FieldType.number, sortable: true, minWidth: 100 }
];
... rest of the code
}
id 为effort-driven 的行是放置图标的位置。换句话说,当您将数据集合(通常是 json 对象数组)推送到表时,键名为 effort-driven 的数据对象的值将被赋予 ID 为 effort-driven 的列。此外,对于每个传递给列的值,myCustomCheckmarkFormatter 方法会重新格式化它(例如 0 -> false 或 null -> 未填充)并将其放置到相应表的单元格中。看看下面的方法:
// create my custom Formatter with the Formatter type
const myCustomCheckmarkFormatter: Formatter<DataItem> = (_row, _cell, value) => {
// you can return a string of a object (of type FormatterResultObject), the 2 types are shown below
return value ? `<i class="fa fa-fire red" aria-hidden="true"></i>` : { text: '<i class="fa fa-snowflake-o" aria-hidden="true"></i>', addClasses: 'lightblue', toolTip: 'Freezing' };
};
如您所见,当调用该方法时,它会返回一个图标,例如<i class="fa fa-fire red" aria-hidden="true"></i>,该图标放置在表格的单元格中。