WiceGrid 3.6.0.pre4 examples

External filters

Filters can also be detached from the grid table. This is a 3-step process.

  1. First, define the grid with helper define_grid instead of grid . Everything should be done the same way as with grid, but every column which will have an external filter, add detach_with_id: :some_filter_name in the column definition.
  2. Then use grid_filter(grid, :some_filter_name) to render filters.
  3. Finally, use render_grid(@grid) to actually output the grid table .
  • # encoding: utf-8
    class DetachedFiltersController < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task)
      end
    end
    
  • .well
      %h2= current_page_title
      %p
        Filters can also be detached from the grid table. This is a 3-step process.
    
      %ol
        %li
          First, define the grid with helper
          %code define_grid
          instead of
          %code grid
          \. Everything should be done the same way as with
          %code grid, but every column which will have an external filter, add
          %code detach_with_id: :some_filter_name
          in the
          %code column
          definition.
    
        %li
          Then use
          %code grid_filter(grid, :some_filter_name)
          to render filters.
    
        %li
          Finally, use
          %code render_grid(@grid)
          to actually output the grid table
          \.
    
    = show_code
    
    = render   'grid'
    
    
    .row
      .col-md-2
        ID:
      .col-md-10
        = grid_filter @tasks_grid, :id_filter
    
    .row
      .col-md-2
        Title:
      .col-md-3
        = grid_filter @tasks_grid, :title_filter
      .col-md-7
    
    
    .row
      .col-md-2
        Description:
      .col-md-3
        = grid_filter @tasks_grid, :description_filter
      .col-md-7
    
    .row
      .col-md-2
        Archived:
      .col-md-10
        = grid_filter @tasks_grid, :archived_filter
    
    
    .row
      .col-md-2
        Due date:
      .col-md-10
        = grid_filter @tasks_grid, :due_date
    
    
    .row-fluid
      .col-md-12
        .external-buttons
          %button.btn.btn-primary.wg-external-submit-button{'data-grid-name' => 'grid'} Submit
          %button.btn.btn-default.wg-external-reset-button{'data-grid-name' => 'grid'} Reset
    
    .row-fluid
      .col-md-12
    
        = render_grid(@tasks_grid)
    
  • <%= define_grid(@tasks_grid, hide_submit_button: true, hide_reset_button: true) do |g|
    
      g.column name:  'ID', attribute: 'id', detach_with_id: :id_filter
    
      g.column name:  'Title', attribute: 'title', detach_with_id: :title_filter
    
      g.column  name:  'Description', attribute: 'description', detach_with_id: :description_filter
    
      g.column  name:  'Archived', attribute: 'archived', detach_with_id: :archived_filter do |task|
        task.archived? ? 'Yes' : 'No'
      end
    
    
      g.column name:  'Due Date', attribute: 'due_date', detach_with_id: :due_date do |task|
        task.due_date.to_s(:short)
      end
    
    
      g.column   do |task|
        link_to('Edit', edit_task_path(task))
      end
    
    end -%>
    
ID:
Title:
Description:
Archived:
Due date:

IDTitle DescriptionArchivedDue Date
61-80 / 500 show all
90commodi et quisConsequatur soluta eligendi et consequatur.No30 MayEdit
428commodi omnis temporeEsse sint deleniti a rerum est praesentium unde.No 5 OctEdit
288consectetur dolores delectusQuia vel vitae dolorum iusto illo velit.No26 JulEdit
299consequaturExercitationem voluptatem sint ad.No16 MarEdit
345consequatur est sequiConsectetur libero quia ut dicta.No28 AugEdit
460consequatur nemoVel minus voluptatem facere voluptatem sit.No 3 AugEdit
236consequatur quisquamMinus mollitia ab quia soluta provident aut tempora aut.No26 MayEdit
482consequuntur eumMaiores quo voluptatibus rerum ipsam consequatur.No 5 JunEdit
331consequuntur ipsa quiVoluptatem et quo fugiat sint dignissimos ut provident soluta.No 1 FebEdit
280corporisVoluptate et necessitatibus distinctio et.No30 MayEdit
219corrupti magni voluptatemFugit ut nihil quae quaerat qui.No22 AprEdit
30corrupti molestiae abRepellat ipsa quis quam alias dolores itaque.No 2 MarEdit
80corrupti officiaDolore odit consequatur dolores quia deleniti veniam.No29 SepEdit
464culpaError deleniti qui quaerat sint.No17 AprEdit
361culpaQuaerat sit tempore deleniti amet rerum unde sunt.No25 AprEdit
88culpaOccaecati aut eum vero quasi dolorem.No19 OctEdit
269culpa assumendaOmnis voluptatem atque et mollitia a.No15 JunEdit
401cum deserunt nesciuntMolestiae quasi totam voluptatem in esse dignissimos ut.Yes 4 MarEdit
261cumque voluptasQuod distinctio iusto quia quas voluptatem est.No 3 AugEdit
296cupiditate in minimaSit aspernatur tempore id.Yes17 MarEdit

Fork me on GitHub