WiceGrid 3.6.0.pre4 examples

View helpers to access records on the current page and all pages

Method current_page_records sent to the grid object returns a list of all ActiveRecord objects currently displayed on the page.

Method all_pages_records returns a list of all ActiveRecord objects throughout all pages of the current selection. all_pages_records causes an additional SQL query to be executed and has to be used with care.

Both methods can be used after the grid definition only.

  • # encoding: utf-8
    class IntegrationWithApplicationViewController < ApplicationController
      def index
        @tasks_grid = initialize_grid(Task,
          include: [:priority, :status, :project, :assigned_users],
          order: 'statuses.name',
          name: 'g',
          per_page: 10,
          custom_order: {
            'tasks.priority_id' => 'priorities.name',
            'tasks.status_id' => 'statuses.position',
            'tasks.project_id' => 'projects.name'
          }
        )
      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
        Method
        %code current_page_records
        sent to the grid object returns a list of all ActiveRecord objects currently displayed on the page.
      %p
        Method
        %code all_pages_records
        returns a list of all ActiveRecord objects throughout all pages of the current selection.
        %code all_pages_records
        causes an additional SQL query to be executed and has to be used with care.
      %p Both methods can be used after the grid definition only.
    
    = show_code
    
    = render   'grid'
    
    .row-fluid
      .col-md-6
        .well
          - current_page_records = @tasks_grid.current_page_records
          = current_page_records.size
          records on the current page:
          = current_page_records.map(&:id).to_sentence
    
      .col-md-6
        .well
          - all_pages_records = @tasks_grid.all_pages_records
          = all_pages_records.size
          records throughout all pages:
          = all_pages_records.map(&:id).to_sentence
    
    
IDTitlePriorityStatusProject NameArchivedAdded

1-10 / 500 show all
80corrupti officiaUrgentAssignedSuper GameNo12 Mar 12:37
149omnis errorAnecdoticDuplicateSuper GameNo12 Mar 12:37
206quia ipsum maximeVerifiedUltimate WebsiteNo12 Mar 12:37
257et nihilHighDuplicateSuper GameNo12 Mar 12:37
269culpa assumendaHighCancelledDivine FirmwareNo12 Mar 12:37
297dolores magnam eosAnecdoticAssignedSuper GameNo12 Mar 12:37
391aut estLowDuplicateUltimate WebsiteNo12 Mar 12:37
409dolore etNormalPostponedUltimate WebsiteNo12 Mar 12:37
52eos temporibus omnisLowResolvedSuper GameNo13 Mar 12:37
318beataeVerifiedDivine FirmwareNo13 Mar 12:37
10 records on the current page: 80, 149, 206, 257, 269, 297, 391, 409, 52, and 318
500 records throughout all pages: 80, 149, 206, 257, 269, 297, 391, 409, 52, 318, 83, 136, 233, 454, 462, 27, 62, 97, 390, 115, 201, 319, 365, 132, 412, 4, 148, 177, 428, 463, 21, 57, 152, 224, 453, 466, 160, 281, 359, 3, 16, 231, 348, 411, 13, 335, 59, 448, 474, 11, 151, 220, 263, 302, 336, 377, 425, 70, 99, 118, 122, 413, 194, 364, 432, 472, 18, 44, 133, 387, 167, 284, 310, 386, 394, 19, 147, 173, 179, 396, 398, 17, 64, 89, 190, 248, 76, 187, 322, 358, 94, 265, 361, 374, 471, 107, 113, 117, 143, 109, 218, 334, 48, 84, 93, 250, 446, 451, 73, 112, 184, 261, 436, 498, 126, 146, 243, 301, 350, 447, 78, 300, 496, 42, 86, 130, 229, 327, 353, 2, 105, 171, 444, 41, 50, 252, 349, 408, 460, 135, 163, 185, 186, 223, 410, 421, 497, 158, 204, 316, 36, 207, 354, 355, 373, 385, 141, 178, 183, 244, 299, 420, 455, 63, 144, 153, 332, 399, 500, 15, 208, 221, 415, 174, 304, 343, 393, 450, 486, 5, 139, 162, 228, 246, 305, 170, 311, 333, 434, 435, 475, 53, 65, 330, 337, 344, 357, 419, 495, 47, 172, 211, 216, 225, 262, 293, 23, 230, 400, 465, 198, 209, 255, 8, 168, 176, 214, 278, 370, 422, 480, 46, 51, 276, 328, 342, 406, 438, 90, 338, 71, 416, 30, 125, 320, 426, 440, 49, 191, 295, 363, 429, 29, 196, 286, 403, 482, 100, 175, 296, 321, 351, 479, 129, 458, 477, 33, 79, 256, 270, 347, 491, 28, 81, 95, 128, 131, 219, 14, 66, 166, 325, 366, 484, 75, 120, 287, 367, 38, 39, 69, 202, 226, 275, 407, 37, 159, 181, 372, 483, 499, 7, 40, 134, 155, 298, 478, 56, 110, 273, 362, 380, 430, 68, 165, 215, 326, 381, 467, 280, 303, 306, 423, 445, 452, 492, 371, 487, 61, 193, 205, 368, 427, 433, 457, 6, 314, 324, 356, 383, 392, 116, 312, 341, 31, 259, 288, 401, 443, 22, 119, 260, 271, 272, 414, 235, 282, 345, 108, 140, 188, 200, 213, 268, 375, 476, 490, 1, 10, 74, 182, 376, 26, 404, 439, 441, 464, 240, 292, 395, 88, 197, 309, 12, 242, 253, 388, 417, 123, 189, 384, 418, 58, 203, 389, 493, 25, 54, 285, 313, 339, 20, 239, 251, 431, 494, 98, 142, 289, 329, 405, 456, 24, 138, 150, 245, 279, 402, 424, 60, 96, 290, 489, 43, 77, 101, 111, 437, 82, 195, 222, 237, 145, 236, 397, 449, 461, 481, 104, 127, 154, 266, 9, 32, 164, 169, 307, 317, 468, 91, 92, 103, 114, 124, 294, 227, 234, 247, 258, 210, 238, 254, 360, 442, 469, 485, 55, 102, 217, 473, 85, 137, 157, 352, 87, 277, 283, 379, 34, 156, 212, 267, 315, 382, 45, 67, 121, 199, 241, 264, 323, 331, 369, 35, 72, 249, 291, 378, 180, 308, 340, 488, 106, 232, 346, 161, 192, 274, 459, and 470

Fork me on GitHub