WiceGrid 3.6.0.pre4 examples

Joined tables

Use :include in :initialize_grid to include associated tables. :include can be a single association name, an array of association names. If you need to join tables to joined tabes, use hashes, for example: include: [:priority, :status, {project: :customer}]

To define a column from a joined table, use :assoc to specify a the corresponding association. If you need to join a table to a joined table, list associations in an array on the correct order (look at the customer column).

You can drop a block if you don't need any special markup.

  • # encoding: utf-8
    class JoiningTablesController < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          # You can omit includes if they are all mentioned in :assoc in the view
          # includes: [:priority, :status, {project: :customer}],
          conditions: { archived: false },
          order: 'id'
        )
      end
    end
    
  • .well
      %h2= current_page_title
      %p
        Use
        %code :include
        in
        %code :initialize_grid
        to include associated tables.
        %code :include
        can be a single association name, an array of association names.
        If you need to join tables to joined tabes, use hashes, for example:
        %code include: [:priority, :status, {project: :customer}]
    
      %p
        To define a column from a joined table, use
        %code :assoc
        to specify a the corresponding association.
        If you need to join a table to a joined table,
        list associations in an array on the correct order
        (look at the customer column).
      %p
        You can drop a block if you don't need any special markup.
    
    = show_code
    
    = render   'grid'
    
  • <%= grid(@tasks_grid, show_filters: :always) do |g|
    
      g.column name:  'ID', attribute: 'id', filter: false
    
      g.column name:  'Title', attribute: 'title'
    
      g.column name:  'Priority', attribute: 'name',  assoc: :priority
    
      g.column name:  'Status', attribute: 'name', assoc: :status
    
      g.column name:  'Project Name', attribute: 'name', assoc: :project
    
      g.column name:  'Customer', attribute: 'name', assoc: [:project, :customer]
    
    
      g.column name:  'Assigned To', attribute: 'name', assoc: :assigned_users do |task|
        task.assigned_users.collect{|user| user.name}.to_sentence
      end
    
      g.column   do |task|
        link_to('Edit', edit_task_path(task))
      end
    end -%>
    
IDTitlePriority StatusProject NameCustomerAssigned To
1-20 / 449 show all
2ut sintAnecdoticAssignedDivine FirmwareSkyNetKoobus Venter and Sarah LivingstoneEdit
22etAnecdoticCancelledSuper GameMNUPiet SmitEdit
23exercitationem autAnecdoticClosedDivine FirmwareSkyNetKoobus Venter and Fundiswa MhlangaEdit
40dolorAnecdoticClosedSuper GameMNUPiet SmitEdit
51harum qui possimusAnecdoticCancelledDivine FirmwareSkyNetKoobus Venter and Dirk MichaelsEdit
69similique placeat ipsaAnecdoticDuplicateDivine FirmwareSkyNetGrey Bradnam, Koobus Venter, and Dirk MichaelsEdit
76totamAnecdoticNewUltimate WebsiteMNUFundiswa Mhlanga and ObesandjoEdit
92est praesentiumAnecdoticClosedSuper GameMNUChristopher JohnsonEdit
102inventore eligendi voluptasAnecdoticNewDivine FirmwareSkyNetSarah LivingstoneEdit
103molestiaeAnecdoticCancelledDivine FirmwareSkyNetKoobus Venter and Dirk MichaelsEdit
106laboriosam enimAnecdoticStartedDivine FirmwareSkyNetKoobus VenterEdit
116dolorem consecteturAnecdoticClosedUltimate WebsiteMNUObesandjo and Dirk MichaelsEdit
129voluptates minima molestiaeAnecdoticVerifiedUltimate WebsiteMNUDirk Michaels, Dirk Michaels, and ObesandjoEdit
132quiaAnecdoticCancelledUltimate WebsiteMNUGrey Bradnam and Wikus van de MerweEdit
140mollitiaAnecdoticNewUltimate WebsiteMNUDirk MichaelsEdit
149omnis errorAnecdoticDuplicateSuper GameMNUPiet SmitEdit
67officia quo maioresAnecdoticCancelledSuper GameMNUEdit
58atque etAnecdoticStartedDivine FirmwareSkyNetEdit
3aliquam repudiandaeAnecdoticAssignedDivine FirmwareSkyNetEdit
14repellat consequatur velitAnecdoticNewUltimate WebsiteMNUEdit

Fork me on GitHub