It is possible to override the default ordering by custom sql code. "Status Name" in the first table is done by the length of the status name. Ordering "Status Name" in the second table is actually replaced by ordering by column.
# encoding: utf-8 class CustomOrderingController < ApplicationController def index @status_grid1 = initialize_grid(Status, order: 'statuses.name', custom_order: { 'statuses.name' => 'length( ? )' } ) @status_grid2 = initialize_grid(Status, name: 'g2', order: 'statuses.name', custom_order: { 'statuses.name' => 'statuses.position' } ) end end
<%= grid(grid, show_filters: :always) do |g|
g.column name: 'ID', attribute: 'id', filter: false
g.column name: 'Status Name', attribute: 'name'
g.column name: 'Created' do |status|
status.created_at.to_s(:db) if status.created_at
end
end -%>
:css table.my-grid { border: 1px solid red; } table.my-grid tr.my-header { background-color: #ebebeb; } .well %h2= current_page_title %p It is possible to override the default ordering by custom sql code. "Status Name" in the first table is done by the length of the status name. Ordering "Status Name" in the second table is actually replaced by ordering by column. = show_code .row .col-md-6 = render 'grid', grid: @status_grid1 .col-md-6 = render 'grid', grid: @status_grid2
ID | Status Name | Created | |
---|---|---|---|
1-9 / 9 | |||
10 | New | 2015-09-27 12:37:17 | |
17 | Closed | 2015-09-27 12:37:17 | |
12 | Started | 2015-09-27 12:37:17 | |
18 | Verified | 2015-09-27 12:37:17 | |
11 | Assigned | 2015-09-27 12:37:17 | |
13 | Resolved | 2015-09-27 12:37:17 | |
16 | Postponed | 2015-09-27 12:37:17 | |
15 | Cancelled | 2015-09-27 12:37:17 | |
14 | Duplicate | 2015-09-27 12:37:17 |
ID | Status Name | Created | |
---|---|---|---|
1-9 / 9 | |||
10 | New | 2015-09-27 12:37:17 | |
11 | Assigned | 2015-09-27 12:37:17 | |
12 | Started | 2015-09-27 12:37:17 | |
13 | Resolved | 2015-09-27 12:37:17 | |
14 | Duplicate | 2015-09-27 12:37:17 | |
15 | Cancelled | 2015-09-27 12:37:17 | |
16 | Postponed | 2015-09-27 12:37:17 | |
17 | Closed | 2015-09-27 12:37:17 | |
18 | Verified | 2015-09-27 12:37:17 |