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
21-40 / 500 Alle rijen tonen
98aperiam rerumRerum quaerat eligendi voluptatem.Yes19 JulEdit
309architecto esse autNisi quam et amet dolorem in assumenda.No12 FebEdit
145asperioresSit consectetur dignissimos blanditiis velit aperiam est ratione reprehenderit.No 8 OctEdit
457asperiores qui nonIllum consequatur laboriosam iusto praesentium sed dolore.No16 MayEdit
444asperiores quisIure est soluta deserunt sunt.Yes29 FebEdit
185aspernaturAutem minus et libero inventore.No23 MarEdit
388aspernatur dolores velIn velit quis optio exercitationem aspernatur et pariatur.No27 FebEdit
20aspernatur eligendi adipisciMaiores perspiciatis tempore et aut sapiente eaque.No 8 JunEdit
11aspernatur estVoluptatem error inventore officia rem nemo qui.Yes21 JunEdit
376assumendaBlanditiis tempora qui ut ex.No25 SepEdit
437atVoluptatem rerum eos illo voluptatem labore autem consectetur consequatur.No29 FebEdit
402atReiciendis ut reprehenderit occaecati quia voluptatum error debitis.No29 AprEdit
71atRatione distinctio eligendi quaerat.No13 JulEdit
404at aliquam corruptiVitae ut excepturi earum eum officia quidem repellat perspiciatis.No27 JanEdit
396at consequatur quaeratNostrum enim iusto architecto numquam.No24 FebEdit
316at enim ullamUt minima dolor molestias ut.No 6 JunEdit
58atque etEst alias est non debitis omnis voluptatem.No29 MarEdit
466autIllum corporis occaecati quia quo aut ratione voluptatem.No21 MarEdit
161autCommodi delectus eaque quia occaecati molestiae voluptate ut qui.No25 AprEdit
93autId vero doloremque animi unde.No20 SepEdit

Fork me on GitHub