Created
May 9, 2016 02:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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