Mensa
Fast and awesome tables, with pagination, sorting, filtering and custom views.
Wanted features:
- [X] very fast
- [X] row-links
- [X] sorting
- [X] tables without headers (and without most of the above)
- [ ] column sorting
- [ ] filtering (of multiple columns, single is done)
- [ ] view selection and exports per view
- [ ] group by
- [ ] sum/max/min
- [ ] tables backed by arrays (of ActiveModel)
Usage
Add tables in your app/tables folder, inheriting from ApplicationTable. This in turn should inherit from Mensa::Base.
class UserTable < ApplicationTable
definition do
model User # implicit from name
order { name: :desc}
column(:name) do
attribute :name # Optional, we can deduct this from the column name
filter do
collection -> { }
scope -> { where(name: ...) }
end
end
column(:nr_of_roles) do
attribute "roles_count" # We use a database column here
end
end
end
Currently mensa depends on satis, but that is something we might remove in a future version. You can show your tables on the page using the following:
= sts.table :users
Fast
Mensa selects only the data it needs, based on the columns. Sometimes it needs additional columns to do it's work, but you don't want them displayed.
This can be done by adding internal true to the column definition.
column :born_on do
internal true # Needed for age below
end
column :age do
attribute "EXTRACT(YEAR FROM AGE(born_on))::int"
end
Installation
Add this line to your application's Gemfile:
gem "mensa"
And then execute:
$ bundle
Or install it yourself as:
$ gem install mensa
Always use bundle to install the gem. Next use the install generator to install migrations, add an initializer and do other setup:
$ bin/rails g mensa:install
Contributing
Contribution directions go here.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).