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
81-100 / 500 show all
76totamDistinctio et pariatur non est consequatur enim.No 6 SepEdit
349et similiqueDistinctio sunt ut doloribus adipisci rerum in.No24 MayEdit
238namDolor culpa laboriosam enim omnis ipsa.No 6 OctEdit
383omnis vel delectusDolorem amet et et in iusto autem occaecati.No17 FebEdit
421reiciendis dolorum quodDoloremque alias quis reiciendis dicta ipsa libero doloribus rerum.Yes28 MayEdit
332autem etDolorem qui qui repudiandae eveniet mollitia est exercitationem rerum.No28 AugEdit
33voluptatemDolorem saepe et aspernatur.No11 JunEdit
80corrupti officiaDolore odit consequatur dolores quia deleniti veniam.No29 SepEdit
136exercitationem distinctio quiDolores dolor amet quis a facilis asperiores.No 1 AprEdit
133optioDolores officia in et quam aliquid repellat rerum.No 3 OctEdit
123suscipit sunt deseruntDolores quasi minus fugiat reprehenderit et consequatur.No20 MarEdit
176vitae ducimus consequunturDolores tenetur consequatur nihil minima id delectus consequatur et.No25 MayEdit
245iure utDolores veniam quia sint est a.No 4 JulEdit
118hicDolores voluptatem nobis repudiandae consequatur fugiat autem voluptas.No 7 JunEdit
192eumDoloribus sequi facere aut dolor sed quae quos.No19 SepEdit
168adDolorum id sint assumenda quos consectetur aut eveniet.No 6 OctEdit
422harum enimDolorum illum enim eum numquam aut nihil et perferendis.No14 JulEdit
281velitDolorum quaerat asperiores itaque quibusdam libero aspernatur sed eius.No14 FebEdit
198eaDolorum voluptates quae veniam porro repudiandae nam eos qui.No 5 JulEdit
162quia nihil laboreDolor vitae perspiciatis error occaecati accusamus aperiam.No19 MarEdit

Fork me on GitHub