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
    
  • .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)
    
  • <%= 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:

IDTitleDescriptionArchivedDue Date
21-40 / 500 show all
21et rerum laborumVelit consequatur quas sunt perspiciatis quae nihil.No29 AprEdit
22etReiciendis non officia aut omnis quia minima.No28 AugEdit
23exercitationem autVoluptatum aut earum at est deserunt.No21 MayEdit
24voluptate culpaEt velit ut libero dolores.No24 JunEdit
25ab quiFugit id error esse.No 3 MayEdit
26quia mollitia delenitiFugit voluptatem recusandae soluta voluptatum consequuntur est voluptatem quas.No 9 JunEdit
27eum velUllam tenetur culpa error fugit sunt.No29 MayEdit
28laborum enim voluptasDignissimos sed laudantium in consequatur quaerat molestias optio maxime.No23 MayEdit
29etEst nesciunt accusantium repudiandae est officia ipsa.No 3 JulEdit
30corrupti molestiae abRepellat ipsa quis quam alias dolores itaque.No 2 MarEdit
31debitis pariatur illoTemporibus velit id et porro dolor.Yes29 AugEdit
32voluptatem ipsam liberoBlanditiis omnis enim voluptas fugit molestiae.No19 SepEdit
33voluptatemDolorem saepe et aspernatur.No11 JunEdit
34illo voluptasEsse et fuga voluptate eveniet qui.No 2 JulEdit
35modiAnimi quod iste sunt.Yes 8 MayEdit
36placeatQuia aut eligendi aliquid.No29 MayEdit
37etIncidunt eum consequatur qui et quis.No 6 JunEdit
38minima doloribus sedEst ipsum aut quam libero dolorem praesentium ut repellendus.No16 OctEdit
39praesentium et idExpedita laborum incidunt natus.No27 MarEdit
40dolorSapiente voluptas aspernatur non nulla illo aperiam et.No14 MayEdit

Fork me on GitHub