woylie / flop_phoenix

Components for pagination, sortable tables and filter forms using Phoenix, Ecto and Flop
MIT License
385 stars 43 forks source link

Default filter op: ilike_and #287

Closed ghenry closed 11 months ago

ghenry commented 11 months ago

Hi all,

Where do I actually set this?

https://hexdocs.pm/flop/Flop.Schema.html#module-filtering

In my FilterComponent or in handle_event("update-filter", params, socket)?

I have a component like this https://github.com/woylie/flop_phoenix#filter-forms

I'd like to get a default.

Thanks.

ghenry commented 11 months ago

Nevermind!

I scrolled up in:

iex(1)> h(Flop.Phoenix.filter_fields/1 )

and can see:

Field configuration

The fields can be passed as atoms or keywords with additional options.

fields={[:name, :email]}

Or

fields={[
  name: [label: gettext("Name")],
  email: [
    label: gettext("Email"),
    op: :ilike_and,
    type: "email"
  ],
  age: [
    label: gettext("Age"),
    type: "select",
    prompt: "",
    options: [
      {gettext("young"), :young},
      {gettext("old"), :old)}
    ]
  ]
]}

Available options:

• label - Defaults to the humanized field name. • op - Defaults to :==. • type - Defaults to an input type depending on the Ecto type of the filter field.

Any additional options will be passed to the input component (e.g. HTML classes or a list of options).

Going to leave this here for my future self.