Skip to content

Commit

Permalink
Update doc according to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 18, 2024
1 parent 1b1fc9c commit a26aa1a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
4 changes: 1 addition & 3 deletions lib/datagrid/columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
module Datagrid
# Defines a column to be used for displaying data in a Datagrid.
#
# class UserGrid
# include Datagrid
#
# class UserGrid < ApplicationGrid
# scope do
# User.order("users.created_at desc").joins(:group)
# end
Expand Down
12 changes: 5 additions & 7 deletions lib/datagrid/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ module Datagrid
# Defines the accessible attribute that is used to filter
# the scope by the specified value with specified code.
#
# class UserGrid
# include Datagrid
#
# class UserGrid < ApplicationGrid
# scope do
# User
# end
Expand Down Expand Up @@ -64,13 +62,13 @@ module Datagrid
#
# `:date` - Converts value to a date. Supports the `:range` option to accept date ranges.
#
# filter(:created_at, :date, range: true, default: proc { [1.month.ago.to_date, Date.today] })
# filter(:created_at, :date, range: true, default: proc { 1.month.ago.to_date..Date.today })
#
# == Datetime
#
# `:datetime` - Converts value to a timestamp. Supports the `:range` option to accept time ranges.
#
# filter(:created_at, :datetime, range: true, default: proc { [1.hour.ago, Time.now] })
# filter(:created_at, :datetime, range: true, default: proc { 1.hour.ago..Time.now })
#
# == Enum
#
Expand All @@ -93,7 +91,7 @@ module Datagrid
#
# `:integer` - Converts value to an integer. Supports the `:range` option.
#
# filter(:posts_count, :integer, range: true, default: [1, nil])
# filter(:posts_count, :integer, range: true, default: (1..nil))
#
# == String
#
Expand Down Expand Up @@ -123,7 +121,7 @@ module Datagrid
# Example:
#
# filter(:id, :integer, header: "Identifier")
# filter(:created_at, :date, range: true, default: proc { [1.month.ago.to_date, Date.today] })
# filter(:created_at, :date, range: true, default: proc { 1.month.ago.to_date..Date.today })
#
# = Localization
#
Expand Down
36 changes: 15 additions & 21 deletions lib/datagrid/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ module Datagrid
#
# Use the built-in partial:
#
# = datagrid_form_for @grid, url: report_path, other_form_for_option: value
# = datagrid_form_with model: @grid, url: report_path, other_form_for_option: value
#
# {#datagrid_form_for} supports the same options as Rails `form_for`.
# {#datagrid_form_with} supports the same options as Rails `form_with`.
#
# === Advanced Method
#
# You can use Rails built-in tools to create a form. Additionally, Datagrid provides helpers to generate input/select elements for filters:
#
# - form_for UserGrid.new, method: :get, url: users_path do |f|
# - form_with model: UserGrid.new, method: :get, url: users_path do |f|
# %div
# = f.datagrid_label :name
# = f.datagrid_filter :name # => <input name="grid[name]" type="text"/>
Expand All @@ -73,7 +73,7 @@ module Datagrid
#
# To create a report form:
#
# - form_for @report, method: :get, url: users_path do |f|
# - form_with model: @report, method: :get, url: users_path do |f|
# - @report.filters.each do |filter|
# %div
# = f.datagrid_label filter
Expand Down Expand Up @@ -156,7 +156,7 @@ module Datagrid
#
# Modify the form for AJAX:
#
# = datagrid_form_for @grid, html: {class: 'js-datagrid-form'}
# = datagrid_form_with model: @grid, html: {class: 'js-datagrid-form'}
# .js-datagrid-table
# = datagrid_table @grid
# .js-pagination
Expand All @@ -179,9 +179,8 @@ module Datagrid
#
# app/views/datagrid/
# ├── _enum_checkboxes.html.erb # datagrid_filter for filter(name, :enum, checkboxes: true)
# ├── _form.html.erb # datagrid_form_for
# ├── _form.html.erb # datagrid_form_with
# ├── _head.html.erb # datagrid_header
# ├── _order_for.html.erb # datagrid_order_for
# ├── _range_filter.html.erb # datagrid_filter for filter(name, type, range: true)
# ├── _row.html.erb # datagrid_rows/datagrid_rows
# └── _table.html.erb # datagrid_table
Expand All @@ -198,18 +197,14 @@ module Datagrid
# category.orders.sum(:subtotal) / category.orders.count
# end
#
# The `:description` option is not built into Datagrid, but you can implement it by modifying the column header
# partial `app/views/datagrid/_header.html.erb` like this:
# The `:description` option is not built into Datagrid, but you can implement it
# by adding the following to partial `app/views/datagrid/_header.html.erb`:
#
# %tr
# - grid.html_columns(*options[:columns]).each do |column|
# %th{class: datagrid_column_classes(grid, column)}
# = column.header
# - if column.options[:description]
# %a{data: {toggle: 'tooltip', title: column.options[:description]}}
# %i.icon-question-sign
# - if column.order && options[:order]
# = datagrid_order_for(grid, column, options)
# <% if column.options[:description] %>
# <a data-toggle="tooltip" title="<%= column.options[:description] %>">
# <i class="icon-question-sign"></i>
# </a>
# <% end %>
#
# This modification allows the `:description` tooltip to work with your chosen UI and JavaScript library.
# The same technique can be applied to filters by calling `filter.options` in corresponding partials.
Expand All @@ -228,8 +223,7 @@ module Datagrid
#
# This allows you to define a custom `row_class` method in your grid class, like this:
#
# class IssuesGrid
# include Datagrid
# class IssuesGrid < ApplicationGrid
# scope { Issue }
#
# def row_class(issue)
Expand Down Expand Up @@ -396,7 +390,7 @@ def datagrid_form_with(**options)
#
# * <tt>:partials</tt> - Path for form partial lookup.
# Default: 'datagrid'.
# * All options supported by Rails <tt>form_for</tt> helper
# * All options supported by Rails <tt>form_with</tt> helper
# @deprecated Use {#datagrid_form_with} instead.
# @param grid [Datagrid] grid object
# @param [Hash] options
Expand Down

0 comments on commit a26aa1a

Please sign in to comment.