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
    
    
IDTitlePriorityStatus Project NameArchivedAdded

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

Fork me on GitHub