DataTables row details in Ruby on Rails - how to separate HTML from Javascript -


i using datatables jquery plugin in ruby on rails project (directly, not through datatables-rails gem) , need display row details explained here: https://datatables.net/examples/server_side/row_details.html

in case, after calling $("#table_id").datatable(), use format() function in .js file pass data display row.child:

/* formatting function row details */ function format(d) {     // `d` original data object 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, looks messy html in .js asset file. want understand if there way extract html (possibly in partial).

sure can. use form_for or simple_form_for create form in template (make partial if wish). , in js code need call $("#table_id").datatable() (of course table_id id of table here, , can pass in options @ same time).


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -