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:

IDTitleDescription ArchivedDue Date
461-480 / 500 Sýna allt
460consequatur nemoVel minus voluptatem facere voluptatem sit.No 3 AugEdit
450distinctio aspernaturVel perspiciatis exercitationem dolorem ducimus.No16 MayEdit
284illo explicaboVel quibusdam quia repellendus eligendi at.No22 SepEdit
483laborum dictaVeniam reiciendis laboriosam voluptas accusamus qui.No28 FebEdit
126qui voluptatum atqueVeniam ut eaque commodi sint esse.No22 FebEdit
15est ut autVero distinctio voluptatem veritatis.No30 OctEdit
341est cumVero dolore iusto ducimus ea illum dicta consequuntur.No 1 SepEdit
308optio idVero non non saepe.No10 MayEdit
392velit vitaeVero tenetur ex et totam nam natus aperiam doloremque.No27 AugEdit
274eos sint ametVitae nihil et quos aliquam possimus porro qui.No 7 AugEdit
404at aliquam corruptiVitae ut excepturi earum eum officia quidem repellat perspiciatis.No27 JanEdit
187quodVitae voluptates voluptas et aliquam aperiam eos.No29 JunEdit
95quibusdam beatae adVoluptas aperiam beatae architecto provident cum.Yes 6 MarEdit
285iure veniam numquamVoluptas eius possimus eos voluptates asperiores voluptatem perferendis.No 2 FebEdit
462provident doloremque laudantiumVoluptas nihil enim placeat.No22 JanEdit
62eum velit saepeVoluptas voluptas nesciunt in eos eum inventore.No18 OctEdit
56sitVoluptate enim perspiciatis nihil nisi necessitatibus quo dignissimos.No10 SepEdit
280corporisVoluptate et necessitatibus distinctio et.No30 MayEdit
195nihilVoluptate magnam autem iusto rerum ipsa distinctio praesentium odio.No 2 AugEdit
451expedita nihilVoluptate maiores et sapiente.No 1 AugEdit

Fork me on GitHub