WiceGrid 3.6.0.pre4 examples

Custom ordering

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 NameCreated
1-9 / 9
10New2015-09-27 12:37:17
11Assigned2015-09-27 12:37:17
12Started2015-09-27 12:37:17
13Resolved2015-09-27 12:37:17
14Duplicate2015-09-27 12:37:17
15Cancelled2015-09-27 12:37:17
16Postponed2015-09-27 12:37:17
17Closed2015-09-27 12:37:17
18Verified2015-09-27 12:37:17
IDStatus Name Created
1-9 / 9
10New2015-09-27 12:37:17
11Assigned2015-09-27 12:37:17
12Started2015-09-27 12:37:17
13Resolved2015-09-27 12:37:17
14Duplicate2015-09-27 12:37:17
15Cancelled2015-09-27 12:37:17
16Postponed2015-09-27 12:37:17
17Closed2015-09-27 12:37:17
18Verified2015-09-27 12:37:17

Fork me on GitHub