WiceGrid 3.6.0.pre4 examples

Initial conditions and ordering

Use :order and :order_direction in initialize_grid to define by which column the grid should be ordered once it is loaded initially.

Use :conditions in initialize_grid to define the subset of records shown in the grid.

  • # encoding: utf-8
    class Basics6Controller < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          order: 'tasks.title',
          order_direction: 'desc',
          conditions: { archived: false },
          per_page: 20
        )
      end
    end
    
  • <%= grid(@tasks_grid) do |g|
    
      g.column name:  'ID', attribute: 'id', filter: false
    
      g.column name:  'Title', attribute: 'title'
    
      g.column  name:  'Description', attribute: 'description'
    
      g.column  name:  'Archived', attribute: 'archived' do |task|
        task.archived? ? 'Yes' : 'No'
      end
    
      g.column name:  'Due Date', attribute: 'due_date', filter: false
    
    
      g.column   do |task|
        link_to('Edit', edit_task_path(task))
      end
    end -%>
    
  • .well
      %h2= current_page_title
      %p
        Use
        %code :order
        and
        %code :order_direction
        in
        %code  initialize_grid
        to define by which column the grid should be ordered once it is loaded initially.
    
      %p
        Use
        %code :conditions
        in
        %code  initialize_grid
        to define the subset of records shown in the grid.
    
    = show_code
    
    .row-fluid
      .col-md-12
        = render   'grid'
IDTitle DescriptionArchivedDue Date
441-449 / 449 show all
147adipisci ut asperioresSed sed ullam blanditiis aut consequatur mollitia ipsam et.No2016-08-24Edit
346adipisci at nesciuntEligendi facilis ut consequatur.No2016-10-14Edit
86adipisciConsectetur optio rerum facilis explicabo enim consequatur delectus iste.No2016-02-07Edit
168adDolorum id sint assumenda quos consectetur aut eveniet.No2016-10-06Edit
370accusantium error exercitationemMolestiae eos quibusdam quod id voluptatem eius.No2016-01-24Edit
426accusantium eligendiDebitis dolore id eos tempora.No2016-09-01Edit
436accusantiumCorrupti qui mollitia temporibus.No2016-10-01Edit
63accusamusPraesentium quod ipsum error odit.No2016-09-17Edit
25ab quiFugit id error esse.No2016-05-03Edit

Fork me on GitHub