Users (Basic) Time Sheets (Advanced) Issues (API)
-
-
Total: 100
Id Email Name Disabled Actions
1 dusti_pfeffer@ryandare.co.uk Winfred Franecki No Delete
2 jeffie.grady@pfefferschmeler.com Imelda Heidenreich Yes Delete
3 louvenia_gorczany@towne.name Tamika Cronin No Delete
4 fredericka@padberg.com Shane Glover No Delete
5 echo_ryan@blicknicolas.co.uk Raquel Runolfsson No Delete
6 normand_gleichner@mertz.ca Deja Corkery No Delete
7 emmy.halvorson@flatley.ca Royce Spencer No Delete
8 vincenza@homenick.info Claudette Hagenes No Delete
9 mariel.jacobson@koepp.us Grace Kris Yes Delete
10 maia@casperfadel.biz Dorthey Turner No Delete
11 therese@blickjacobi.biz Sylvester Hane Yes Delete
12 judy_gleason@kshlerin.biz Li Considine No Delete
13 barb.osinski@kreiger.name Rebecca Rempel Yes Delete
14 marni.okeefe@stamm.co.uk Pearlie McGlynn No Delete
15 sally@blick.biz Marna Ritchie No Delete
16 shan@schmidt.us Maryanna Medhurst Yes Delete
17 alison_lubowitz@bogisich.name Rossana Schneider Yes Delete
18 jennine_hane@hoppe.biz Benita Thompson Yes Delete
19 crystle@mosciski.biz Jon Lindgren No Delete
20 felica@wintheiser.com Wiley Wuckert No Delete
21 lanell_bernhard@runolfsdottirpredovic.com Dania Crona Yes Delete
22 ronni@torphybahringer.com Dona Gutkowski Yes Delete
23 buford@casperrobel.co.uk Clifton Hintz No Delete
24 elenor.rolfson@hilpertsanford.info Mi Prosacco No Delete
25 bennie@miller.info Carlota Gottlieb No 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