WiceGrid 3.6.0.pre4 examples

CSV export and external filters

CSV export works with define_grid and external filters, too.

  • # encoding: utf-8
    class CsvAndDetachedFiltersController < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          name: 'grid',
          enable_export_to_csv: true,
          csv_field_separator: ';',
          csv_file_name: 'tasks'
        )
    
        export_grid_if_requested('grid' => 'grid')
      end
    end
    
  • <%= 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 -%>
    
  • .well
      %h2= current_page_title
      %p
        CSV export works with
        %code define_grid
        and external filters, too.
    
    = 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-10
        = grid_filter @tasks_grid, :title_filter
    
    .row
      .col-md-2
        Description:
      .col-md-10
        = grid_filter @tasks_grid, :description_filter
    
    .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
      .col-md-12
        %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
        %button.btn.btn-primary.wg-external-csv-export-button{'data-grid-name' => 'grid'} Export To CSV
    
    %p
    
    .row
      .col-md-12
    
    
    
        = render_grid(@tasks_grid)
    
ID:
Title:
Description:
Archived:
Due date:

ID TitleDescriptionArchivedDue Date
1-20 / 500 show all
1impedit aperiam liberoEst necessitatibus tempora ut.No27 JulEdit
2ut sintAssumenda ut in commodi nihil ratione odio voluptatibus ea.No21 OctEdit
3aliquam repudiandaeConsequatur iste similique dolorum ducimus ut.No20 AprEdit
4nisi quiQuas assumenda eos molestiae recusandae eveniet sit sint.No16 MayEdit
5dicta pariaturCorporis iure repellat fuga omnis alias iusto aut voluptatum.No 4 MarEdit
6molestiae autemExplicabo aut ratione omnis voluptatem officia itaque dicta aut.Yes26 OctEdit
7ut veniamMolestiae qui qui quo occaecati.No 4 AugEdit
8nullaNatus sint inventore culpa fugiat occaecati est distinctio.No22 MayEdit
9quisquam in isteEt fugiat blanditiis facilis asperiores et.No 7 MarEdit
10rerum occaecatiCum aperiam voluptas aut.No14 AugEdit
11aspernatur estVoluptatem error inventore officia rem nemo qui.Yes21 JunEdit
12explicabo hicPorro in nisi ea sunt consequatur est incidunt et.No15 AprEdit
13utEst voluptas impedit perferendis excepturi aliquid doloremque.No18 JulEdit
14repellat consequatur velitError autem et deleniti nihil maxime voluptatem eius eveniet.No10 JanEdit
15est ut autVero distinctio voluptatem veritatis.No30 OctEdit
16omnisPossimus voluptas tempore sed mollitia neque vero nesciunt.No 5 FebEdit
17itaque suscipit commodiEt ut eveniet deleniti voluptatem omnis ea magnam et.No23 AugEdit
18necessitatibus commodiLabore dolor et cumque quos.No28 MarEdit
19id rem eaIn odio quia laborum quam dicta nulla.Yes14 AprEdit
20aspernatur eligendi adipisciMaiores perspiciatis tempore et aut sapiente eaque.No 8 JunEdit

Fork me on GitHub