wice_grid
wice_grid copied to clipboard
Show blank_slate when all records filtered out
The blank_slate
feature only works when there are no records in the database. I would like it to also show the blank slate when no records are returned due to filters—at least when using detached filters. I realize this behavior is documented in the readme, but I don't see its value. If this is considered a feature, perhaps it could be an option.
i am currently not working on this plugin. But this should be a simple feature/configuration. Look at line
if rendering.blank_slate_handler && grid.resultset.size == 0 && !grid.filtering_on?
in wice_grid_view_helpers.rb
Running or not running the last check will do the trick.
I will accept a pull request.
Thanks for the tip! I actually found that on my own and tried disabling the last boolean. It does show the blank slate instead of the grid, but it also makes all the filters disappear. I tried to investigate further into the filter generation, but I wasn't able to figure it out.
As a workaround, is it possible to determine from the grid instance whether the filtered result set is empty? I tried empty?
, size
, count
, do_count
, resultset.size
, resultset.count
, even resultset_without_paging_with_user_filters
—all return > 0 even when the table is empty.
If there are no records, you could display the grid title row and filters as well as the text "No records found" by looking for this in wice_grid_view_helpers.rb#grid_html:
grid.output_buffer << '</tfoot><tbody>'
and inserting this line immediately after it:
grid.output_buffer << "<tr><td colspan='#{rendering.number_of_columns + (no_rightmost_column ? 0 : 1)}'>No records found</td></tr>" if grid.resultset.length == 0