Total: 100
| Id | Name | Disabled | Actions | |
|---|---|---|---|---|
| 40 | lawanda@goldner.com | Micheal Jenkins | Yes | |
| 58 | lekisha_bradtke@bogisich.name | Vernia Dietrich | Yes | |
| 28 | jerry_roberts@townewilkinson.us | Terisa Ruecker | Yes | |
| 36 | stefani@walsh.us | Thaddeus Stanton | Yes | |
| 49 | debrah@gerhold.us | Lynell Stamm | Yes | |
| 57 | alleen@parker.name | Bridgett Reilly | Yes | |
| 2 | jeffie.grady@pfefferschmeler.com | Imelda Heidenreich | Yes | |
| 26 | gwenn@gislasonbrown.info | Jamie Stehr | Yes | |
| 32 | nicol@daniel.ca | Milagros Lemke | Yes | |
| 35 | roscoe_feest@beattymante.info | Treena Wolf | Yes | |
| 48 | russel_prohaska@padberg.name | Malvina Zulauf | Yes | |
| 13 | barb.osinski@kreiger.name | Rebecca Rempel | Yes | |
| 50 | tonia@cruickshank.biz | Alise Rolfson | Yes | |
| 52 | ronnie.littel@grimesbraun.co.uk | Shannon Botsford | Yes | |
| 16 | shan@schmidt.us | Maryanna Medhurst | Yes | |
| 17 | alison_lubowitz@bogisich.name | Rossana Schneider | Yes | |
| 18 | jennine_hane@hoppe.biz | Benita Thompson | Yes | |
| 9 | mariel.jacobson@koepp.us | Grace Kris | Yes | |
| 29 | wyatt_jacobi@leuschke.name | Jeanne Witting | Yes | |
| 21 | lanell_bernhard@runolfsdottirpredovic.com | Dania Crona | Yes | |
| 22 | ronni@torphybahringer.com | Dona Gutkowski | Yes | |
| 11 | therese@blickjacobi.biz | Sylvester Hane | Yes | |
| 43 | yong@miller.co.uk | Almeta Adams | Yes | |
| 47 | mozelle@mclaughlin.ca | Jamison Hagenes | Yes | |
| 59 | ebony.orn@dooley.info | Britney Ruecker | Yes |
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)},
)
filter(:registered_at, :date, range: true)
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}", class: 'link', target: '_blank'
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|
content_tag(:div) do
link_to "Delete", "javascript:alert('Oh common! This is a demo.')", class: 'btn btn-sm btn-primary'
end
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_with model: 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