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
    
    
IDTitle PriorityStatusProject NameArchivedAdded

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

Fork me on GitHub