Users (Basic) Time Sheets (Advanced) Issues (API)
-
-
Total: 100
Id Email Name Disabled Actions
26 gwenn@gislasonbrown.info Jamie Stehr Yes Delete
27 jolynn@considine.biz Elsa Goodwin No Delete
28 jerry_roberts@townewilkinson.us Terisa Ruecker Yes Delete
29 wyatt_jacobi@leuschke.name Jeanne Witting Yes Delete
30 dollie@damore.com Elenora Brakus No Delete
31 kenneth@nienowconsidine.biz Elise Waelchi No Delete
32 nicol@daniel.ca Milagros Lemke Yes Delete
33 lisette_stroman@turnerfeil.co.uk Brigid McLaughlin No Delete
34 al_flatley@marvin.ca Cristopher Dooley No Delete
35 roscoe_feest@beattymante.info Treena Wolf Yes Delete
36 stefani@walsh.us Thaddeus Stanton Yes Delete
37 natisha.schimmel@frami.biz Reinaldo Heidenreich No Delete
38 norine@croninkassulke.co.uk Jackson Kozey No Delete
39 fern@monahanleffler.name Gonzalo Blanda No Delete
40 lawanda@goldner.com Micheal Jenkins Yes Delete
41 marget.parisian@hudson.com Elida Zulauf No Delete
42 leesa@ernser.com Tami Gibson No Delete
43 yong@miller.co.uk Almeta Adams Yes Delete
44 robt@cole.co.uk Juliana Hauck No Delete
45 shawnna@homenick.info Huong McKenzie No Delete
46 halina_schumm@gottliebdenesik.us Nelson Leannon No Delete
47 mozelle@mclaughlin.ca Jamison Hagenes Yes Delete
48 russel_prohaska@padberg.name Malvina Zulauf Yes Delete
49 debrah@gerhold.us Lynell Stamm Yes Delete
50 tonia@cruickshank.biz Alise Rolfson Yes Delete

Grid:

class UsersGrid < ApplicationGrid

  #
  # Scope
  #

  scope do
    User
  end

  #
  # Filters
  #

  filter(:id, :string, multiple: ',')
  filter(:email, :string)
  filter(:disabled, :xboolean)
  filter(:registration_type, :enum, select: User::REGISTRATION_TYPES.map {|r| [r.humanize, r]})
  filter(
    :logins_count, :integer,
    range: true,
    default: proc { User.minimum(:logins_count)..User.maximum(:logins_count)},
    input_options: {type: 'number'},
  )
  filter(:registered_at, :date, range: true, input_options: {type: 'date'})
  filter(:condition, :dynamic, header: "Dynamic condition")
  column_names_filter(header: "Extra Columns", checkboxes: true)

  #
  # Columns
  #

  column(:id, mandatory: true)
  column(:email, mandatory: true) do |model|
    format(model.email) do |value|
      link_to value, "mailto:#{value}"
    end
  end
  column(:name, mandatory: true)
  column(:disabled, mandatory: true) do
    disabled? ? "Yes" : "No"
  end

  column(:registration_type) do |record|
    record.registration_type.humanize
  end
  column(:logins_count)
  column(:registered_at) do |record|
    format(record.registered_at.to_date) do |value|
      value.strftime("%b %d, %Y")
    end
  end
  column(:age, header: "Registration Age") do |record|
    age = (DateTime.now.in_time_zone - record.registered_at) / 1.day
    "#{age.to_i} days"
  end

  column(:actions, html: true, mandatory: true) do |record|
    link_to "Delete", "javascript:alert('Oh common! This is a demo.')", class: 'btn btn-primary'
  end
end

Controller:

class UsersController < ApplicationController
  def index
    @users_grid = UsersGrid.new(params[:g]) do |scope|
      scope.page(params[:page])
    end
  end
end

View:

- grid = @users_grid

.grid-index-grid
  %div{class: 'overflow-x-auto p-4 overflow-y-hidden'}
    = datagrid_form_for grid, url: users_path
    .text-xl.m-3
      Total: #{grid.assets.total_count}
    = datagrid_table(grid, html: {class: 'table'})
    = paginate grid.assets, window: 3
  %div
    = render :partial => "shared/source", :object => grid