How to display an image instead of a bool value in a cell in datatable? The datatable is associated with a datasource.
Asked
Active
Viewed 3,651 times
1 Answers
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
-
I'm running into the same issue and the above code doesn't work. Is there another way? – codeBarer Nov 06 '13 at 18:54
-
Sorry, I haven’t worked with YUI in several years. It’s possible this has changed. Hopefully someone more current on it can comment. – Nate Nov 07 '13 at 00:31
-
1Found some info on YUI3. All I had to do was add an extra object called allowHTML: true after formatter. – codeBarer Nov 07 '13 at 04:01
-
@codeBarer +1 thanks a lot i was searching for that HTML option – NetStarter Dec 02 '13 at 14:53