datagrid icon indicating copy to clipboard operation
datagrid copied to clipboard

Ajax enum/select filter

Open rbdmorgan opened this issue 4 years ago • 1 comments

Is it possible to wire up a dynamic enum/select filter to something like this:

https://select2.org/data-sources/ajax

Would be useful when you have a proc/query that returns a lot of results.

rbdmorgan avatar Jul 30 '21 15:07 rbdmorgan

IMO providing endpoints to automatically load the options out of the box is doomed to have issues with different formats. I wouldn't do it out of the box.

You can try something like this:

class MyGrid
  filter(:department, :string, input_options: {class: 'js-department-select'})
end

class DepartmentsSelectController
  def index
     render json: departments: Department.where("name like '%#{params[:q]}%'").limit(30).map {|d| {text: d.name, id: d.id}
  end
$('.js-department-select').select2({
  ajax: {
    url: 'https://api.github.com/search/repositories',
  }
});

bogdan avatar Aug 02 '21 15:08 bogdan