javascript - Ransack sort_link with ajax ignore pre-selected filters on rails -
i have added sort dropdown box existing rails app has multiple ransack filter options built in. facing following 2 problems:
problem 1 when select sort function dropdown box, sorts db ignores selected filters. displays full db sort function applied not reflecting filters applied.
problem 2 have added following code dropdown("toggle")
javascript dropdown box closes after users click sort function , works well; code included in javascipt, sort works first time clicked.
any suggestions?
index.erb
<%= search_form_for @q, remote: true, :builder => simpleform::formbuilder |f| %> <%= f.input :brand_eq, label: false, :collection => project::brand_range.map{|k,v| [v,v]}, prompt: "all", input_html: { class: "form-control" } %> <div class="dropdown pull-right"> <button class="btn btn-default dropdown-toggle" type="button" id="dlabel" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> <span id="dropdown_title">sort</span> <span class="caret pull-right"></span> </button> <ul class="dropdown-menu" aria-labelledby="dlabel"> <li><%= sort_link(@q, :price, 'price (highest lowest)', {default_order: :desc}, :remote => true, hide_indicator: true) %></li> <li><%= sort_link(@q, :price, 'price (lowest highest)', {default_order: :asc}, :remote => true, hide_indicator: true) %></li> </ul> </div>
'
javascript
$(document).ready(function(){ $('div.dropdown ul.dropdown-menu li a').click(function (e) { $('#dropdown_title').html($(this).html()); $(this).dropdown("toggle"); }) });
update problem 2 [solution] replaced $(this).dropdown("toggle");
$('[data-toggle="dropdown"]').parent().removeclass('open');
worked.
controller
def index @q = project.ransack(params[:q]) @projects = @q.result(distinct: true) @projects = kaminari.paginate_array(@projects).page(params[:page]).per(30) end
Comments
Post a Comment