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 Name ArchivedAdded

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

Fork me on GitHub