
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Datagrid Version 2.0.0 is here.
A really mighty and flexible ruby library that generates reports including admin panels, analytics and data browsers:
Datagrid DEMO application is available live! Demo source code.
In order to create a grid:
class UsersGrid < Datagrid::Base
scope do
User.includes(:group)
end
filter(:category, :enum, select: ["first", "second"])
filter(:disabled, :xboolean)
filter(:group_id, :integer, multiple: true)
filter(:logins_count, :integer, range: true)
filter(:group_name, :string, header: "Group") do |value|
self.joins(:group).where(groups: {name: value})
end
column(:name)
column(:group, order: -> { joins(:group).order(groups: :name) }) do |user|
user.name
end
column(:active, header: "Activated") do |user|
!user.disabled
end
end
Basic grid api:
report = UsersGrid.new(
group_id: [1,2],
logins_count: [1, nil],
category: "first",
order: :group,
descending: true
)
report.assets # => Array of User instances:
# SELECT * FROM users WHERE users.group_id in (1,2) AND
# users.logins_count >= 1 AND
# users.category = 'first'
# ORDER BY groups.name DESC
report.header # => ["Name", "Group", "Activated"]
report.rows # => [
# ["Steve", "Spammers", false],
# [ "John", "Spoilers", false],
# ["Berry", "Good people", true]
# ]
report.data # => [ header, *rows]
report.to_csv # => Yes, it is
In order to create a report, you need to define:
Default scope of objects to filter and display.
In common case it is ActiveRecord::Base
(or any other supported ORM)
subclass with some generic scopes like:
scope do
User.includes(:group)
end
Each filter definition consists of:
Datagrid supports different type of filters including:
Each column is represented by name and code block to calculate the value.
column(:activated, header: "Active", order: "activated", after: :name) do
self.activated?
end
Some formatting options are also available. Each column is sortable.
Datagrid has a builtin generator:
rails g datagrid:scaffold skills
That gives you some code to play with out of the box:
create app/grids/skills_grid.rb
create app/controllers/skills_controller.rb
create app/views/skills/index.html.erb
route resources :skills
insert app/assets/stylesheet/application.css
In order to get a control on datagrid built-in views run:
rails g datagrid::views
All advanced frontend things are described in:
If you have a question of any kind, just make an issue and describe your problem in details.
If you are interested in contributing to this project, please follow the instructions here.
Like datagrid?
Follow the repository on GitHub.
Read author blog.
FAQs
Unknown package
We found that datagrid demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.