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:

IDTitleDescription ArchivedDue Date
1-20 / 500 Sýna allt
209fugaA amet qui quas aliquam neque.Yes 1 MarEdit
287sint non dolorAb aut rerum ut sequi tenetur voluptate repellat non.No10 MayEdit
204error earum quiAb labore rerum quisquam rerum enim magni.No28 AugEdit
429ipsamAccusamus a vel suscipit facere officia doloribus.No17 MarEdit
403et praesentium temporeAccusamus omnis odit in cumque soluta aliquam.No20 OctEdit
452illum et voluptatemAccusamus quis quis sapiente distinctio aut et quaerat asperiores.Yes 3 FebEdit
294fugiat evenietAccusamus ut et nesciunt sit corrupti.No10 JunEdit
415voluptatemAccusantium mollitia dolorem nesciunt ipsa libero dolor.No16 JunEdit
74molestiaeAd dolores occaecati fuga ratione praesentium quo.No 5 MarEdit
69similique placeat ipsaAlias ratione autem ut impedit non nihil itaque eaque.No19 MarEdit
336aut quis aspernaturAliquam fuga similique facilis accusamus reprehenderit.No21 AprEdit
130esse rationeAliquid dolore aut magnam voluptatum ad.No14 AprEdit
431vitae repudiandaeAliquid nihil aliquam architecto eos delectus placeat.No21 MayEdit
321quis est autemAmet veniam quia molestias eum modi impedit rerum ad.No 9 MarEdit
413voluptateAnimi esse amet nihil ad nobis voluptatum.No10 MarEdit
222voluptasAnimi odio ad et nisi quod perferendis natus possimus.No17 JanEdit
35modiAnimi quod iste sunt.Yes 8 MayEdit
43impedit atque minimaAperiam expedita autem porro enim veniam.Yes15 AugEdit
137molestiaeArchitecto praesentium ut dolorem illo facere rerum numquam provident.Yes30 JanEdit
229omnis commodiArchitecto qui voluptatum vel et.No26 AprEdit

Fork me on GitHub