Sorting of users depending on

Hi,

  I have attached an image file with this port. Here, Currently I am
sorting (order) users depending on email id. I would like to sort the
users depending on checkbox status so that selected (checked) users will
be listed first and then other emails will be listed in the order of
email.

<% User.all( :order => :email, :conditions => ( @current_user.excelfore?
? [] : ["role != 'excelfore'"] ) ).each_with_index do |u,i| %>
    <tr<%= ' class="even_row"' if i.even? %>>
      <td class="checkbox">
        <input id="checkbox_<%= i %>" type="checkbox" <%=
'checked="checked"' if @group.users.include?( u ) %> onchange="if (
this.checked ) {
            <%= remote_function( :url => { :action => :add_user, :id =>
@group.id, :user => u.id },
                                 :before => "checkbox_onchange_before(
#{ i } )",
                                 :success => "checkbox_onchange_success(
#{ i }, 'user added' )",
                                 :failure => "checkbox_onchange_failure(
#{ i }, 'add user' )",
                                 :complete =>
"checkbox_onchange_complete( #{ i } )" ) %>;
          } else {
            <%= remote_function( :url => { :action => :remove_user, :id
=> @group.id, :user => u.id },
                                 :before => "checkbox_onchange_before(
#{ i } )",
                                 :success => "checkbox_onchange_success(
#{ i }, 'user removed' )",
                                 :failure => "checkbox_onchange_failure(
#{ i }, 'remove user' )",
                                 :complete =>
"checkbox_onchange_complete( #{ i } )" ) %>;
          }" />
      </td>
      <td><span class="checkbox_label" onclick="checkbox_click( <%= i %>
)"><%= u.email %></span></td>
      <td>
        <% if u.name.present? %>
          <span class="checkbox_info" onclick="checkbox_click( <%= i %>
)"><%= u.name %></span>
        <% end %>
      </td>
      <td id="status_<%= i %>" class="checkbox_status"></td>
    </tr>
  <% end %>

Attachments:
http://www.ruby-forum.com/attachment/7369/sortingofusers.jpg

The first step is to get that finder out of the view, and move it into
the User model. Then you can call it on the @current_user instance and
do all of your sorting and shuffling in one place:

Class User < AR::Base
  def accessible_users
    return [] unless role == "excelfore"
    User.all( :order => :email, :conditions => ( ["role !=
'excelfore'"] ) ).sort_by { |u| u.receiving_group_email? }
  end

  def receiving_group_email?
    # some calculation here that returns whether or not users are at
the top of the list - or even better, move it into the conditions of
the finder...
  end
end

# in the view
<% @current_user.accessible_users.each_with_index do |u,i| %> .... etc

Michael Pavling wrote in post #1060114:

Currently I am
sorting (order) users depending on email id. I would like to sort the
users depending on checkbox status so that selected (checked) users will
be listed first and then other emails will be listed in the order of
email.

The first step is to get that finder out of the view, and move it into
the User model. Then you can call it on the @current_user instance and
do all of your sorting and shuffling in one place:

Class User < AR::Base
  def accessible_users
    return [] unless role == "excelfore"
    User.all( :order => :email, :conditions => ( ["role !=
'excelfore'"] ) ).sort_by { |u| u.receiving_group_email? }
  end

  def receiving_group_email?
    # some calculation here that returns whether or not users are at
the top of the list - or even better, move it into the conditions of
the finder...
  end
end

# in the view
<% @current_user.accessible_users.each_with_index do |u,i| %> .... etc

Hi Michael,
Thanks for your reply...

Can I do it by using sorttable.js ? I have included table headers,
sorttable.js. And also I have changed the table class to
class="sortable". But it is not working.

Do I need to give any link to the column headers?

<script src="sorttable.js" type="text/javascript"></script>
<table class="sortable" border="0" cellpadding="2" cellspacing="0">
  <thead>
    <tr>
    <th><%= "Select"%></th>
              <th><%= "Email" %></th>
          <th><%= "Name" %></th>
                </tr>
  </thead>

Thank you,
Ajit

No idea - that's nothing to do with Rails AFAIK - it's all front-end
stuff; JS manipulation of data that's been sent to the browser.