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
    
    
IDTitlePriority StatusProject NameArchivedAdded

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

Fork me on GitHub