bogdan / datagrid

Gem to create tables grids with sortable columns and filters
MIT License
1.02k stars 115 forks source link

HTML options to filters #246

Closed andresulivam closed 6 years ago

andresulivam commented 6 years ago

Hi! How to add html options to filters? I tried a some tags like: html_options: {} html_attributes: {} html: {} Can I do this?

bogdan commented 6 years ago

Yes, you need to modify the built-in partials for that rake datagrid:copy_partials. Then modify _form.html.erb partial and access options with filter.options[:html_options]. In this way you can add any custom options to filter.

ericksm3 commented 6 years ago

Hello, bogdan! Is there a way to add html attributes on the datagrid generated inputs? Like a "placeholder" for example.

bogdan commented 6 years ago

Run rake datagrid:copy_partials. Change _form.html.erb:

-      <%= f.datagrid_filter filter %>
+      <%= f.datagrid_filter filter, placeholder: filter.options[:placeholder] %>

Now you can use :placeholder option in filter definition:

filter(:value, :string, placeholder: "Specify Value")
ericksm3 commented 6 years ago

Thank you so much! It worked :)

andresulivam commented 6 years ago

Thank you, Bogdan!