Skip to content

Instantly share code, notes, and snippets.

@birchestx
Created May 9, 2016 02:45
Show Gist options
  • Save birchestx/4a3ea8c86c3618ba9cf64ffd5da83210 to your computer and use it in GitHub Desktop.
Save birchestx/4a3ea8c86c3618ba9cf64ffd5da83210 to your computer and use it in GitHub Desktop.
datatable click on row to edit in Rails. Wraps the url in the <tr> element
In datatable declaration:
fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
row_id = ($(nRow).attr("id")).split('_').pop();
$(nRow).attr("data-edit-location", '<%= controller_path %>/' + row_id + '/edit');
return nRow;
}
In document.ready:
$('tbody').on('click', 'tr', function () {
var edit_location = $(this).data("edit-location");
window.location = edit_location;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment