srv
srv

Reputation: 435

How to display images in datatable?

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

Upvotes: 1

Views: 3659

Answers (1)

Nate
Nate

Reputation: 19030

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.

Upvotes: 5

Related Questions