WiceGrid 3.6.0.pre4 examples

Callback to process records throughout all pages on demand

In addition to the with_paginated_resultset callback there is callback with_resultset .

Just like with_paginated_resultset it can be defined as a block and as a symbol referring to a method in the controller.

The difference is that the value submitted to the method or the callback is not a list of all records but an ActiveRelation object which can be used to obtain all records. In the example on this page the list of all records is only obtained when button Show IDs of records throughout all pages is clicked.

Normally with_resultset is used for some kind of background processing. The results of callback are rendered on page only for the sake of the demonstration.

  • # encoding: utf-8
    class ResultsetProcessings2Controller < ApplicationController
      attr_reader :selected_tasks
    
      def index
        @tasks_grid = initialize_grid(Task,
          include: [:priority, :status, :project, :assigned_users],
          order: 'statuses.name',
          name: 'g',
          per_page: 5,
          with_resultset: :process_records,
          custom_order: {
            'tasks.priority_id' => 'priorities.name',
            'tasks.status_id' => 'statuses.position',
            'tasks.project_id' => 'projects.name'
          }
        )
    
        @selected_tasks = []
      end
    
      protected
    
      def process_records(active_relation)
        if params[:process_selected_tasks]
          @selected_tasks = active_relation.to_a
        end
      end
    end
    
  • <%= grid(@tasks_grid, hide_submit_button: true) do |g|
    
      g.column name:  'ID', attribute: 'id', filter: false
    
      g.column name:  'Title', attribute: 'title', auto_reload:  true
    
      g.column name:  'Priority', attribute: 'priority_id', custom_filter: Priority.to_dropdown, auto_reload:  true do |task|
        task.priority.name if task.priority
      end
    
      g.column name:  'Status', attribute: 'status_id', custom_filter: Status.to_dropdown, auto_reload:  true  do |task|
        task.status.name if task.status
      end
    
      g.column name:  'Project Name', attribute: 'project_id', custom_filter: Project.to_dropdown, auto_reload:  true do |task|
        task.project.name if task.project
      end
    
      g.column  name:  'Archived', attribute: 'archived', auto_reload:  true do |task|
        task.archived? ? 'Yes' : 'No'
      end
    
      g.column name:  'Added', attribute: 'created_at', auto_reload:  true do |task|
        task.created_at.to_s(:short)
      end
    
    end -%>
    
  • .well
      %h2= current_page_title
      %p
        In addition to the
        %a{href:  resultset_processings_path}
          %code with_paginated_resultset
          callback
        there is callback
        %code with_resultset
        \.
    
      %p
        Just like
        %code with_paginated_resultset
        it can be defined as a block and as a symbol referring to a method in the controller.
    
      %p
        The difference is that the value submitted to the method or the callback is not a list of
        all records but an ActiveRelation object which can be used to obtain all records.
    
        In the example on this page the list of all records is only obtained when button
        %code Show IDs of records throughout all pages
        is clicked.
    
      %p
        Normally
        %code with_resultset
        is used
        for some kind of background processing.
        The results of callback are rendered on page only for the sake of the demonstration.
    
    = show_code
    
    = form_tag(resultset_processings2_index_path, method:  :get) do
      = dump_filter_parameters_as_hidden_fields(@tasks_grid)
      = hidden_field :process_selected_tasks, 1
      %button#process.btn.btn-primary{type:  'submit'} Show IDs of records throughout all pages
    
    .example
      = render   'grid'
    
      -unless controller.selected_tasks.blank?
        .row-fluid
          .col-md-12
            .well
              = controller.selected_tasks.size
              records on all pages:
              = controller.selected_tasks.map(&:id).to_sentence
    
IDTitlePriorityStatusProject NameArchivedAdded

491-495 / 500 Alle rijen tonen
439namVerifiedDivine FirmwareNo23 May 12:37
444asperiores quisLowVerifiedSuper GameYes09 Apr 12:37
460consequatur nemoHighVerifiedUltimate WebsiteNo10 Apr 12:37
466autAnecdoticVerifiedDivine FirmwareNo19 Mar 12:37
422harum enimAnecdoticVerifiedSuper GameNo25 Apr 12:37

Fork me on GitHub