1

How to display an image instead of a bool value in a cell in datatable? The datatable is associated with a datasource.

srv
  • 435
  • 1
  • 5
  • 22

1 Answers1

5

You can put any HTML into your cells by using a custom formatter function. Your Column definition might look like this:

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....
];

Also see the Custom Cell Formatting example.

Nate
  • 18,752
  • 8
  • 48
  • 54