0

For example, I use data remote for the pagination like this :

<%= paginate @products, :remote => true %>

It works. But the problem is I have multiple lists to paginate in one page. So, I need a way to send the call to a separate files so I can render the appropriate content. How can I do this?

My index.js.erb :

<% if params[:list] %>
   $('#products').html('<%= escape_javascript render(@products) %>');
   $('#paginator').html('<%= escape_javascript(paginate(@products, remote: true, param_name: 'list' ).to_s) %>');
<% end %>
THpubs
  • 7,804
  • 16
  • 68
  • 143
  • I believe you are talking about different js view template. If so you can do something like this. if request.xhr? render( :partial => "partial_name", :locals => {:products => @products}, :layout => false ) in the controller's action. – Sivanand Kheti Mar 18 '15 at 06:18

1 Answers1

1

For this you need to add another param with paginate.

<%= paginate @products, :remote => true, :param_name => param_name %>

This params name will pass as parameter to controller so you can control which ajax pagination you are calling.

If you are calling same action then on the basis of param name you can change the value of @products also. One more thing you need to consider in your xxxx.js.erb file you need to render paginate object also.

In your js file you can change html on the basis of param also.

- if params[:xxx]
  $('#xxx').html('#{escape_javascript render(:partial =>"partial_name",:locals => { :posts => @products, :param_name => 'xxx'})}');
  $('#xxx #paginator').html('#{escape_javascript(paginate(@products, :remote => true, :param_name => 'xxx').to_s)}');
- if params[:yyy]
  $('#yyy').html('#{escape_javascript render(:partial =>"partial_name",:locals => { :posts => @products, :param_name => 'yyy'})}');
  $('#yyy #paginator').html('#{escape_javascript(paginate(@products, :remote => true, :param_name => 'yyy').to_s)}');

In your controller you should use param_name instead of params page

Dipak Gupta
  • 7,321
  • 1
  • 20
  • 32