laravel-enso / tables

Bulma themed, VueJS powered Datatable with server-side loading and JSON template setup
https://www.laravel-enso.com/examples/table
632 stars 77 forks source link

Custom filters (internalFilters) #227

Closed mauthi closed 3 years ago

mauthi commented 4 years ago

This is a question.

Prerequisites

Description

I found the possibility to create custom filters (like you used id in people table). For this feature I have some questions:

Thx in advance for your help.

aocneanu commented 4 years ago

Hi @mauthi,

We call that internal-filters

They can be dynamic:

  1. You can add filterable attribute on most type of fields and will work automagic

    • boolean
    • string
    • date
    • number
    • enum
  2. Besides that, you can also create custom filters, I'll paste a working sample from a project here, hope is self explanatory.

    "filters": [{
        "label": "Manufacturers",
        "data": "products.manufacturer_id",
        "type": "select",
        "value": [],
        "route": "administration.companies.options",
        "multiple": true,
        "params": {
            "is_manufacturer": true
        }
    }, {
        "label": "Vendor",
        "data": "products.vendor_id",
        "type": "select",
        "value": [],
        "route": "administration.companies.options",
        "multiple": true,
        "params": {
            "is_manufacturer": true
        }
    }, {
        "label": "Competitor",
        "data": "competitorIds",
        "type": "select",
        "value": [],
        "route": "administration.companies.options",
        "multiple": true,
        "custom": true,
        "params": {
            "is_competitor": true
        }
    }],

It should be possible to use both types of filters w/o problems, if used correctly.

Regarding docs, we're waiting for somebody like you to help us integrate this into the docs :)

mauthi commented 3 years ago

Thx for your answer - I will try this soon.

It should be possible to use both types of filters w/o problems, if used correctly.

I think I formulated my question wrong. Question is if it's possible to use a filter like BooleanFilter to trigger internal-filter logic. I mean I have a BooleanFilter "Paid" and if it's true I would like to show all invoices with open_amount = 0, if it's false I would like to show all with open amount != 0. I can easily achieve this with internal-filter but I would like to have the possibility with BooleanFilter component as well.

Regarding docs, we're waiting for somebody like you to help us integrate this into the docs :)

I would love to help, but you can see from my irregular activity here how much time I have :(

aocneanu commented 3 years ago

Any kind of external filter that triggers internal filters logic is not supported, or the scope of either of the filters.

A boolean filters that is external and works, sure, we have tens of that.

mauthi commented 3 years ago

A boolean filters that is external and works, sure, we have tens of that.

I know, I use many of them in my project. But for the use case described above it's not possible to use the boolean filter. There it would make sense for me to define/overwrite the filter logic in backend like you do it with internal filters.

mauthi commented 3 years ago

Do you know what I mean? My goal would be to use filter logic of internal-filters in backend and trigger them via an own component (e.g. something like the boolean filter component) from frontend. The feature of internal-filters is nice, but I can't store predefined scenarios persistent (they are gone after you clear local storage)

aocneanu commented 3 years ago

Maybe you should start clean here and document better this issue.

mauthi commented 3 years ago

ok, will do. Sorry.

mauthi commented 3 years ago

I close this for now - will create a new ticket if necessary.