Users (Basic) Time Sheets (Advanced) Issues (API)
-
-
Total: 100
Id Email Name Disabled Actions
100 oliva@koss.com Penney Schowalter Yes Delete
99 karrie@brakus.us Ashleigh Kris No Delete
98 lashanda_torp@strosin.ca Ethyl Ankunding No Delete
97 morton@hane.com Myriam Von No Delete
96 zonia.gerlach@howe.info Joelle Hodkiewicz No Delete
95 aletha@shanahan.co.uk Palmira Fay No Delete
94 glynda@bosco.info Elisa Wintheiser Yes Delete
93 willena.kuhic@harberrussel.co.uk Eleonore Wisozk No Delete
92 mattie_batz@windler.ca Ophelia Hermiston No Delete
91 karima@swaniawski.ca Felisa Jaskolski Yes Delete
90 fallon.adams@cassin.biz German Murphy Yes Delete
89 kirstin@corkeryparisian.com Verla Friesen No Delete
88 shelli@leuschke.com Crissy Brekke No Delete
87 nelly@nolancremin.us Jewell Swaniawski No Delete
86 rashida.hills@kling.info Tess Nikolaus Yes Delete
85 misti.beier@schuppe.com Bong Witting No Delete
84 zella@blandakohler.us Blake Hoppe No Delete
83 verda@bechtelar.info Tamera Bogan Yes Delete
82 josefa.graham@haag.us Beverlee Auer Yes Delete
81 adrian@hermanromaguera.us Gwendolyn Satterfield No Delete
80 nia.schmitt@luettgen.biz Bok Wolf No Delete
79 zenaida@welchmills.ca Kaye Greenfelder No Delete
78 pia.metz@huel.us Elli Dietrich Yes Delete
77 phung_bradtke@kubblanda.us Desmond Murray No Delete
76 carisa_lueilwitz@leannon.us Awilda Schumm 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