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
    
  • .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
    
    
  • <%= 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 -%>
    
IDTitlePriorityStatusProject NameArchivedAdded

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

Fork me on GitHub