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
101-120 / 500 Sýna allt
317nulla perspiciatis sapienteDolor voluptatibus aut ipsa ad ut.No20 SepEdit
454similique enim odioEa cupiditate sit ex aut laudantium voluptatem.No11 JanEdit
304voluptatibus minimaEa exercitationem molestiae magni corrupti quis aperiam et repellat.No24 SepEdit
298iusto quae ipsamEa nihil vel ea.No14 JunEdit
140mollitiaEa pariatur eveniet omnis quae recusandae consectetur.No 6 OctEdit
276sedEa provident inventore minima quis.No18 JulEdit
343dolorem sit molestiasEaque exercitationem aut dolorem amet.No29 JanEdit
188aliquid adipisciEaque maxime mollitia in vel.No15 AugEdit
443ullam laudantium commodiEaque tempora non quia sit quia perspiciatis mollitia.No25 OctEdit
377quam qui quibusdamEa quia perferendis fuga dolore voluptatum vel vel.No 5 FebEdit
256saepeEarum facere omnis voluptatem dolor ad.No15 FebEdit
160aut voluptatesEarum odio voluptatem nulla.No14 AprEdit
244autem sintEarum quibusdam rerum amet quae laudantium.Yes30 JunEdit
467in error praesentiumEarum temporibus quae laudantium.No 4 FebEdit
425nulla quoEius non asperiores adipisci non quo aspernatur.No30 AprEdit
324natus dicta possimusEligendi et quis aut quasi voluptate tempore temporibus ut.No 4 JunEdit
346adipisci at nesciuntEligendi facilis ut consequatur.No14 OctEdit
371id officiis doloremEnim earum cupiditate suscipit libero.No30 JunEdit
485ut teneturEos corporis voluptate ex sed totam.No13 OctEdit
337estEos dolores ipsum ipsam mollitia.No23 FebEdit

Fork me on GitHub