WiceGrid 3.6.0.pre4 examples

Adding custom rows

It is possible to insert a custom row at the bottom of the grid with last_row and a custom row before or after a certain row with before_row and after_row.

The block of before_row or after_row is executed for each record and if it returns a string.

Both before_row and last_row are expected to return the complete markup for a table row starting with the tr tag.

The first argument for a last_row block and the second argument for before_row and after_row blocks is the number of columns in the grid.

  • # encoding: utf-8
    class AddingRowsController < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          include:  [:priority, :status, :project, :assigned_users],
          order:  'statuses.name',
          custom_order:  {
            'tasks.priority_id' => 'priorities.name',
            'tasks.status_id' => 'statuses.position',
            'tasks.project_id' => 'projects.name'
          }
        )
      end
    end
    
  • .well
      %h2= current_page_title
      %p
        It is possible to insert a custom row at the bottom of the grid with
        %code last_row
        and a custom row before or after a certain row with
        %code before_row
        and
        %code after_row.
      %p
        The block of
        %code before_row
        or
        %code after_row
        is executed for each record and if it returns a string.
      %p
        Both
        %code before_row
        and
        %code last_row
        are expected to return the complete markup for a table row starting with the
        %code tr
        tag.
      %p
        The first argument for a
        %code last_row
        block and the second argument for
        %code before_row
        and
        %code after_row
        blocks is the number of columns in the grid.
    
    = show_code
    
    .row-fluid
      .col-md-12
        = render   'grid'
  • <%= grid(@tasks_grid) do |g|
    
      g.after_row do |task, number_of_columns|
        if task.priority == Priority.urgent
          content_tag(:tr,
            content_tag(:td,
              content_tag(:button, "Panic! \"#{task.title}\" is urgent!", class: "btn btn-danger"),
            colspan: number_of_columns),
           class: 'extra-row')
        else
          nil
        end
      end
    
      g.last_row do |number_of_columns|
        content_tag(:tr,
          content_tag(:td,
            content_tag(:button, "Don't panic", class: "btn btn-info"),
            colspan: 9),
         class: 'last-row')
      end
    
      g.row_attributes do |task|
        if task.priority == Priority.urgent
          {class: 'urgent'}
        end
      end
    
    
      g.column name:  'ID', attribute: 'id', filter: false
    
      g.column name:  'Title', attribute: 'title'
    
      g.column name:  'Priority', attribute: 'priority_id', custom_filter: Priority.to_dropdown do |task|
        task.priority.name if task.priority
      end
    
      g.column name:  'Status', attribute: 'status_id', custom_filter: Status.to_dropdown  do |task|
        task.status.name if task.status
      end
    
      g.column name:  'Project Name', attribute: 'project_id', custom_filter: Project.to_dropdown do |task|
        task.project.name if task.project
      end
    
      g.column  name:  'Archived', attribute: 'archived' do |task|
        task.archived? ? 'Yes' : 'No'
      end
    
      g.column name:  'Added', attribute: 'created_at' do |task|
        task.created_at.to_s(:short)
      end
    
      g.column   do |task|
        link_to('Edit', edit_task_path(task))
      end
    end
    -%>
ID TitlePriorityStatusProject NameArchivedAdded

1-20 / 500 show all
1impedit aperiam liberoCancelledDivine FirmwareNo22 May 12:37Edit
2ut sintAnecdoticAssignedDivine FirmwareNo09 Apr 12:37Edit
3aliquam repudiandaeAnecdoticAssignedDivine FirmwareNo21 Mar 12:37Edit
4nisi quiLowVerifiedDivine FirmwareNo18 Mar 12:37Edit
5dicta pariaturHighPostponedDivine FirmwareNo19 Apr 12:37Edit
6molestiae autemResolvedUltimate WebsiteYes16 May 12:37Edit
7ut veniamHighPostponedUltimate WebsiteNo10 May 12:37Edit
8nullaUrgentResolvedDivine FirmwareNo25 Apr 12:37Edit
9quisquam in isteDuplicateUltimate WebsiteNo07 Jun 12:37Edit
10rerum occaecatiUrgentCancelledSuper GameNo22 May 12:37Edit
11aspernatur estUrgentStartedSuper GameYes24 Mar 12:37Edit
12explicabo hicUrgentPostponedDivine FirmwareNo26 May 12:37Edit
13utHighClosedUltimate WebsiteNo22 Mar 12:37Edit
14repellat consequatur velitAnecdoticNewUltimate WebsiteNo06 May 12:37Edit
15est ut autNewDivine FirmwareNo17 Apr 12:37Edit
16omnisHighAssignedSuper GameNo21 Mar 12:37Edit
17itaque suscipit commodiStartedSuper GameNo30 Mar 12:37Edit
18necessitatibus commodiNormalStartedSuper GameNo27 Mar 12:37Edit
19id rem eaLowVerifiedSuper GameYes29 Mar 12:37Edit
20aspernatur eligendi adipisciHighAssignedUltimate WebsiteNo30 May 12:37Edit

Fork me on GitHub