I know that similar questions have already been asked but my problem seems a bit different or I can't make it work with the answers that are already here. When user clicks on each drop down element the table needs to be sorted by the element which was clicked. And when the page is refreshed, the clicked element should be showed, while now it disappears on refresh. Thanks for any help. Here is the code I already have:
events_controller.rb
def index
@events = account.events.page(params[:page]).per_page(5)
end
events.js
$(function(e){
$(".dropdown-menu li a").on('click', function(){
var selText = $(this).text();
var variable = $(this).parents('.btn-group').find('.dropdown-toggle').html(selText+' <span class="caret"></span>');
});
$('.dropdown-menu a').click(function(e) {
e.preventDefault();
});
});
events/index.html.erb
<div class="btn-group">
<button class="btn">Select</button>
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
<li><a href="#"><%= sortable 'location' %></a></li>
<li><a href="#"><%= sortable 'name'%></a></li>
<li><a href="#"><%= sortable 'city' %></a></li>
</ul>
</button>
</div>