Here's an example custom formatter you could try:
// custom format the DataTable to make it possible to detect click events on individual cells
function clickFormat (row, column, value, class) {
return '<span class="' + class + '" row="' + row + '" column="' + column + '">' + value + '</span>';
}
// iterate over the DataTable and format every cell with the clickFormat
// make sure to do all other formatting first!
for (var i = 0; i < data.getNumberOfRows(); i++) {
for (var j = 0; j < data.getNumberOfColumns(); j++) {
data.setFormattedValue(i, j, clickFormat(i, j, data.getFormattedValue(i, j), 'clickableClass'));
}
}
You will need to have the "allowHtml" option set to true for this to work. You can then attach a click event handler to elements with the "clickableClass" class. Here's an example using jQuery:
$('.clickableClass').on('click', function () {
var row = $(this).attr('row');
var column = $(this).attr('column');
var value = data.getValue(row, column);
alert('You clicked on row ' + row + ', column ' + column + ', which has the value ' + value + '.');
});
I didn't test that, so there could be errors, but it's basically what you need.
On Friday, November 16, 2012 5:20:57 PM UTC-5, Robert Whelan wrote:
I have been trying to figure out how I could implement your suggestion here with the html elements and click listeners. I have been looking at datatable.setCell but I am not sure how I can set the metadata tags attributes or tie the click listeners.
Any advise would be greatly appreciated.
Thanks,