如何在数据表中显示图像?

时间:2009-08-04 08:50:09

标签: yui yui-datatable

如何在数据表中的单元格中显示图像而不是bool值?数据表与数据源相关联。

1 个答案:

答案 0 :(得分:5)

您可以使用自定义formatter功能将任何HTML放入您的单元格中。您的列定义可能如下所示:

var myColumnSet = [
    {
        key: 'active_employee',
        label: 'Active',
        formatter: function(el, oRecord, oColumn, oData) {
            // el is the HTMLElement of the current cell
            // oRecord gives you access to other fields from the
            //    DataSource, e.g.: oRecord.getData('full_name')
            // oData is the value of the current field (active_employee)

            if (oData) {
                el.innerHTML = '<img src="/images/active.png">';
            } else {
                el.innerHTML = '<img src="/images/not-active.png">';
            }
        }
    },
    // other Columns....
];

另见Custom Cell Formatting example

相关问题