Order list item on Rails update with jQuery -
i have sidebar list of room names. can edit room's name in modal. when click update in modal, room name should updated in sidebar , should appear in proper order in list. happen on refresh because of server side rails code. need make work on client side.
it's working fine except sorting. i've tried in update.js.erb file:
$("ul.rooms li").detach().sort(asc_sort).appendto('ul.rooms'); function asc_sort(a, b){ return ($(b).text()) < ($(a).text()) ? 1 : -1; }
that results in each list item appearing twice , newly updated room sorts bottom of list.
here's html looks list item (the room name 1):
<li> <a href="#" class="room" id="room-11"> 1 <span class="badge counter"></span> </a> <a class="cog-link pull-right" style="padding:0 20px 0 2px;" data-remote="true" href="/rooms/11/edit"><i class="glyphicon glyphicon-cog pull-right"></i></a> </li>
doing in chrome nightmare ended using tinysort solve issue: http://tinysort.sjeiti.com/
Comments
Post a Comment