ruby on rails - Render template having Jquery datatables in .js.erb file -
i working on project implementing several reports. report filters remotely submitted action , return results displayed in datatable searching,sorting , pagination.
i have drg.js.erb file having code :
var html = "<%= escape_javascript(render(partial: 'drg_datatable',formats: [:html],locals: {result: @result})) %>"; $("#datatable-result").append(html);
the partial _drg_datatable.html.erb having datatable implemented this. below _drg_datatable.html.erb file :
<% if result %> <table id="results" class="table table-striped table-bordered display"> <% case params[:view] %> <% when "ahfs" %> <%= datatable_ahfs_result(result) %> <% when "drg_code" %> <%= datatable_drg_result(result) %> <% when "inpharmics_id" %> <%= datatable_inpharmics_id_result(result) %> <% when "provider" %> <%= datatable_provider_result(result) %> <% else %> <% end %> </table> <% end %>
the problem facing when render partial _drg_datatable.html.erb using .js.erb file creates table escapes javascript add sorting,pagination , other cool features in jquery datatables. can point me how should go doing ? have tried render partial .js.erb without writing escape_javascript partial not rendered @ all.
you must explicitly call datatable js function in drg.js.erb in order "datatablize" table. ex:
var html = "<%= escape_javascript(render(partial: 'drg_datatable',formats: [:html],locals: {result: @result})) %>"; $("#datatable-result").append(html); $('#results').datatable();
i suppose have like:
$(document).ready(function(){ $('a selector of yours').datatable(); });
somewhere in application's javascripts. runs once, after document load , applies elements existent dom. since adding new table have "re assign" datatable behavior...
Comments
Post a Comment