Sometimes we need to show tables of data in a Rails app, sort of like souped-up spreadsheets. The tables, or grids, should handle tons of records, support searching and filtering, and allow for customization.
Ever try coding a data grid yourself? It’s hard. You need to implement pagination, filtering, searching, ordering, etc., every time. Why not use a pre-built solution and built off of it instead?
Wice Grid is the quickest grid solution out there for Rails. It takes care of both the client and server. It’s not AJAX-y and gorgeous, but it’s functional and reliable.
At Cook Smarts, we used Wice Grid to improve the admin interface without leaping to a full-scale solution like Rails Admin.
For instance, Cook Smarts’ customers can purchase gift certificates for their friends. Site admins need to see all gift certificates and search for particular ones. The easiest way for them to do this is through a data grid.
To get started, check out the Wice Grid page on GitHub.
Getting up and running is easy:
Follow the installation instructions on the Wice GitHub page
Add the grid code to a controller method, with the model whose data should appear in the grid.
@gift_certificates_grid = initialize_grid(GiftCertificate)
Then, add the grid code to a view, referencing the grid you specified in the controller. Add columns, specifying the attribute as the field name in the database and the name as the text to appear in the header of the grid.
<%= grid(@gift_certificates_grid) do |g|
g.column name: "Gift Certificate Code", attribute: "code" do |gift_certificate|
link_to gift_certificate.code, edit_gift_certificate_path(gift_certificate)
g.column name: "Redeemed on", attribute: "redeemed_on" do |gift_certificate|
Customizing the order, filtering, search, and pagination is easy. Check out the Wice Grid GitHub page for instructions.
Wice Grid would be even better if it incorporated AJAX, to avoid page reloads when searching, for instance. However, that is the trade-off for its extremely quick setup.