0

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>
user2645029
  • 63
  • 1
  • 9
  • is sortable a helper method? `<%= sortable 'city' %>` – trh Oct 13 '13 at 16:29
  • Yes, it is a helper method. – user2645029 Oct 13 '13 at 16:34
  • Something other than the code you've listed here is causing you to lose your sorted by item. Are you following a tutorial, is there something else to look at that might be the culprit? – trh Oct 13 '13 at 16:41
  • I followed this: http://stackoverflow.com/questions/13437446/how-to-display-selected-item-in-bootstrap-button-dropdown-title and bootstrap tutorial. Don't have a clue what else might be but I feel like I am missing the value option in html, maybe? – user2645029 Oct 13 '13 at 17:06
  • When you said `it disappear on refresh`, do you mean that the HTML block has actually been removed from the DOM or simply the dropdown does not works? – lkartono Oct 14 '13 at 21:20

0 Answers0