leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 213 forks source link

Hook before export? #166

Closed sridharraman closed 10 years ago

sridharraman commented 10 years ago

Is there someway we can place a hook on the Export functionality so that we can limit the number of records that can be exported?

Our client wants us to limit export functionality to only 50 records and for any result-set with more records, the export should happen through some authorisation.

I wanted to know if there is someway we can get a handle on the export_grid_if_requested method and put in the restrictions there?

Or, even better, do it at the browser itself using some jQuery?

leikind commented 10 years ago

I am afraid I can't think of a quick hack to achieve this goal without modifying the source code of the plugim.

jQuery? How? I don't think so.There is no HTML in the CSV generation mode:

        temp_filename = render_to_string(:partial => template_name)
        temp_filename = temp_filename.strip
        filename = (grid.csv_file_name || grid.name ) + '.csv'
        grid.csv_tempfile.close
        send_file_rails2 temp_filename, :filename => filename, :type => 'text/csv; charset=utf-8'
        grid.csv_tempfile = nil

Implementing this limit shouldn't be a big task though.