Users (Basic) Time Sheets (Advanced) Issues (API)
-
-
Total: 100
Id Email Name Disabled Actions
51 lorrie.vandervort@fritsch.com Cherly Kovacek No Delete
52 ronnie.littel@grimesbraun.co.uk Shannon Botsford Yes Delete
53 maricela_powlowski@rosenbaumswift.ca Lesia Hyatt No Delete
54 marquita@johnston.name Sixta Bashirian No Delete
55 christopher_bogan@kuhn.us Myrtle O'Conner No Delete
56 holli@halvorson.ca Lillie Hamill No Delete
57 alleen@parker.name Bridgett Reilly Yes Delete
58 lekisha_bradtke@bogisich.name Vernia Dietrich Yes Delete
59 ebony.orn@dooley.info Britney Ruecker Yes Delete
60 tyler@langworthweimann.us Kellie Cassin Yes Delete
61 gidget.aufderhar@ondrickamclaughlin.us Flavia Will Yes Delete
62 jae@hahnfarrell.name Salley Kilback No Delete
63 jarvis_johnson@reilly.info Wen Daniel No Delete
64 marilou_kutch@kshlerin.us Isidro McCullough Yes Delete
65 catherine.kertzmann@barrows.us Adrienne Eichmann No Delete
66 andreas@blickward.biz Arnita Smith No Delete
67 sharika@willms.info Shara Labadie No Delete
68 cythia.dickinson@jast.info Cathey Prohaska No Delete
69 danyel.crooks@morissette.co.uk Evangelina Pfeffer No Delete
70 adrian.crona@franecki.name Jarvis Ryan Yes Delete
71 rasheeda@lakin.com Alex Legros Yes Delete
72 buddy.grant@greenfelder.ca Johnny Spinka No Delete
73 alvina_maggio@weimann.name Jewell Kreiger No Delete
74 shaunda.stokes@terry.biz Vivien Murray No Delete
75 rosaura@beahanernser.biz Dahlia Hilll 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