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

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

Fork me on GitHub