I am using DataTables jQuery plugin in a Ruby on Rails project (directly, not through a datatables-rails gem) and I need to display row details as explained here: https://datatables.net/examples/server_side/row_details.html
In my case, after calling $("#table_id").DataTable(), I use this format() function in .js file to pass data for display to the row.child:
/* Formatting function for row details */
function format(d) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr>' +
'<td>' + label_variable1 + ':</td>' +
'<td>' + d.office.name + '</td>' +
'</tr>' +
'<tr>' +
'<td>' + label_variable2 + ':</td>' +
'<td>' + d.office.location + '</td>' +
'</tr>' +
// Several more rows...
'</table>';
}
This works fine, however it looks messy with all this HTML in the .js asset file. I want to understand if there is a way to extract the HTML (possibly in a partial).