WiceGrid 3.6.0.pre4 examples

Action column

You can easily add a column with checkboxes for each row with g.action_column . Normally WiceGrid does not use a form, but its filters work correctly when placed inside a form, so you can use a form to process the selected records while keeping the state of the filters. Another way could be reading the selected checkoxes with the help of a simple javascript.

By default the checkboxes have name "grid_name[selected][]" , but you can change selected to something else with parameter param_name: 'my-parameter-name'

The value of the checkox is the id by default, but you can change it with parameter object_property: 'some_object_property' .

select_all_buttons: false hides the "(de)select all" icons, and html: {class: 'my_class'} changes the css class of the checkboxes.

  • # encoding: utf-8
    class ActionColumnController < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          include: [:priority, :status, :project, :assigned_users],
          name:    'g',
          order:   'id'
        )
    
        if params[:g] && params[:g][:selected]
          @selected = params[:g][:selected]
        end
      end
    end
    
  • .well
      %h2= current_page_title
      %p
        You can easily add a column with checkboxes for each row with
        %code g.action_column
        \.
        Normally WiceGrid does not use a form, but its filters work correctly when placed inside a form, so you can use a form to process
        the selected records while keeping the state of the filters. Another way could be reading the selected checkoxes with the help
        of a simple javascript.
      %p
        By default the checkboxes have name
        %code "grid_name[selected][]"
        , but you can change
        %code selected
        to something else with parameter
        %code param_name:  'my-parameter-name'
      %p
        The value of the checkox is the id by default, but you can change it with parameter
        %code object_property:  'some_object_property'
        \.
      %p
        %code select_all_buttons:  false
        hides the "(de)select all" icons, and
        %code html: {class: 'my_class'}
        changes the css class of the checkboxes.
    
    = show_code
    
    = dump_filter_parameters_as_hidden_fields(@tasks_grid)
    = form_for '#', method:  :get do
    
      - if @selected
        .well
          Selected tasks:
          = @selected.to_sentence
    
      .row-fluid
        .col-md-12
          %p
            %button.btn.btn-default{'type' => 'submit'} Process tasks
    
          = render   'grid'
    
          %p
            %button.btn.btn-default{'type' => 'submit'} Process tasks
    
  • <%= grid(@tasks_grid) do |g|
    
      g.action_column html_check_box: false
      # The default param_name is 'selected', the complete HTTP parameter will be "#{grid_name}[#{param_name}][]"
    
      # Or:
      # g.action_column param_name: :foo, html: {class: 'my_class'},
      #                 select_all_buttons: false, object_property: :id
    
    
      g.column name:  'ID', attribute: 'id', filter_type: :range
    
      g.column name:  'Title', attribute: 'title', negation: true
    
      g.column name:  'Archived', attribute: 'archived' do |rec|
        rec.archived? ? 'Yes' : 'No'
      end
    
    
      g.column name:  'Status', attribute: 'status_id', custom_filter: Status.to_dropdown  do |task|
        task.status.name if task.status
      end
    
      g.column name:  'Project Name', attribute: 'project_id', custom_filter: Project.to_dropdown do |task|
        task.project.name if task.project
      end
    
      g.column name:  'Due Date', attribute: 'due_date'
    
    
      g.column name:  'Added', attribute: 'created_at' do |task|
        task.created_at.to_s(:db)
      end
    
    end -%>
    

IDTitle ArchivedStatusProject NameDue DateAdded


1-20 / 500 show all
25ab quiNoVerifiedSuper Game2016-05-032015-05-29 12:37:19
63accusamusNoNewSuper Game2016-09-172015-04-15 12:37:19
436accusantiumNoAssignedSuper Game2016-10-012015-04-05 12:37:25
426accusantium eligendiNoNewSuper Game2016-09-012015-04-29 12:37:25
370accusantium error exercitationemNoClosedDivine Firmware2016-01-242015-04-25 12:37:24
168adNoClosedUltimate Website2016-10-062015-04-25 12:37:21
86adipisciNoStartedSuper Game2016-02-072015-04-08 12:37:20
346adipisci at nesciuntNoStartedDivine Firmware2016-10-142015-06-18 12:37:24
146adipisci etYesAssignedUltimate Website2016-03-012015-04-06 12:37:21
147adipisci ut asperioresNoNewSuper Game2016-08-242015-03-29 12:37:21
81ad quo dolorNoStartedDivine Firmware2016-05-182015-05-05 12:37:20
59alias liberoNoStartedUltimate Website2016-01-092015-03-23 12:37:19
3aliquam repudiandaeNoAssignedDivine Firmware2016-04-202015-03-21 12:37:18
188aliquid adipisciNoAssignedUltimate Website2016-08-152015-05-21 12:37:21
139aliquid oditNoDuplicateDivine Firmware2016-10-112015-04-19 12:37:20
230aliquid rerum modiYesCancelledUltimate Website2016-07-202015-04-23 12:37:22
215aliquid sed suntYesDuplicateSuper Game2016-07-292015-05-12 12:37:22
79animiNoVerifiedSuper Game2016-05-062015-05-04 12:37:19
447animi accusantium utNoClosedDivine Firmware2016-10-152015-04-06 12:37:26
175aperiam omnisNoCancelledUltimate Website2016-04-172015-05-02 12:37:21


Fork me on GitHub