WiceGrid 3.6.0.pre4 examples

Custom filters (method chains)

An array of symbols submitted to :custom_filter has a special meaning. The first symbol is sent as a method name to EVERY ActiveRecord object. If an object responds to this method, the second method name is sent to the returned value unless it is nil, and so on. The dropdown is populated by the list unique values. The conditions set up by the user are ignored, that is, the records used are all those found on all pages without any active filters. Naturally this can be extremely inneffective and should be used with caution.

  • # encoding: utf-8
    class CustomFilters3Controller < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          include: [:relevant_version, :expected_version, :project],
          conditions: { projects: { id: Project.first.id } },
          custom_order: {
            'tasks.expected_version_id' => 'expected_versions_tasks.name'
          }
        )
      end
    end
    
  • .well
      %h2= current_page_title
      %p
        An array of symbols submitted to
        %code :custom_filter
        has a special meaning. The first symbol is sent as a method name to EVERY ActiveRecord object.
        If an object responds to this method, the second method name is sent to the returned value unless it is nil, and so on.
        The dropdown is populated by the list unique values.
        The conditions set up by the user are ignored, that is, the records used are all those found on all pages without any active filters.
        Naturally this can be extremely inneffective and should be used with caution.
    
    = show_code
    
    .row-fluid
      .col-md-12
        = render   'grid'
  • <%= grid(@tasks_grid) do |g|
    
      g.column name:  'ID', attribute: 'id', filter: false
    
      g.column name:  'Title', attribute: 'title'
    
      g.column name:  'Found in version', assoc: :relevant_version, attribute: 'name', custom_filter: :auto do |task|
        task.relevant_version.name if task.relevant_version
      end
    
      g.column name:  'Expected in version', attribute: 'expected_version_id', custom_filter: [:expected_version, :to_option] do |task|
        task.expected_version.name if task.expected_version
      end
    
      g.column   do |task|
        link_to('Edit', edit_task_path(task))
      end
    end -%>
ID TitleFound in versionExpected in version
1-20 / 150 show all
6molestiae autem1.2Edit
7ut veniam3.0Edit
9quisquam in isteEdit
13ut2.0Edit
14repellat consequatur velit2.02.0Edit
20aspernatur eligendi adipisci3.0Edit
27eum velEdit
29et1.02.0Edit
31debitis pariatur illo1.01.0Edit
32voluptatem ipsam libero2.03.0Edit
33voluptatem1.21.1Edit
36placeat2.0Edit
37et3.03.0Edit
42aut1.2Edit
44id temporibus eligendiEdit
46facere3.0Edit
47temporibus iure delectusEdit
49laborum3.0Edit
54minima in voluptatemEdit
59alias libero3.0Edit

Fork me on GitHub