Changing the html content of a cell onClick?
Changing the html content of a cell onClick?
![jstemper](https://secure.gravatar.com/avatar/278279fd647028c6de25ff5e3983bdd7/?default=https%3A%2F%2Fvanillicon.com%2F278279fd647028c6de25ff5e3983bdd7_200.png&rating=g&size=120)
I have a datatable rendering a master/detail sort of display using code found here.
When I init the table I user a render function to add a "plus" icon to one of the cells. The idea being that when you click on that plus icon the detail expands. This works great. What I am trying to do is change that plus icon to a "minus" icon when the detail table is being shown so that it indicates that you click it to close the detail table.
My onClick function is straight from the examples.
$('#indexTable tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = rollup.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(format(row.data())).show();
tr.addClass('shown');
}
});
The function I call on rendering the column is:
var detail = function (data, type, full, meta) {
if (data != null ) {
return '<i class="fa fa-plus-square-o fa-2x" title="'+data+'"></i>'
} else if (data == null) {
return 'N/A'
}
};
I'm trying to figure out the proper way to change the contents of that rendered column to:
<i class="fa fa-minus-square-o fa-2x" title="'+data+'"></i>