rubanraj54 / vue-bootstrap4-table

Advanced table based on Vue 2 and Bootstrap 4 ⚡️
MIT License
220 stars 58 forks source link

Feature: Initialize Filters with default values #21

Closed sdrig closed 5 years ago

sdrig commented 5 years ago

Hi,

It would be nice feature if filters can be set before fetching data. For example: User open the page with a query param. Like Title=Teacher and have a multi-select filter or free text filter, It could search with {title:"teacher"} params when grid initiated.

rubanraj54 commented 5 years ago

Hi @sdrig ,

Yes it makes sense, I will consider this feature for my next release.

Cheers, Ruby.

rubanraj54 commented 5 years ago

Hey @sdrig,

I implemented this feature in the new release 1.0.30.

Could you please do a test with your application and let me know your feedback and improvements.

Still I didn't updated my documents. So here I describe How you can set initial filter options.

Simple Filter example:

columns: [
    {
        label: "id",
        name: "id",
        filter: {
            type: "simple",
            placeholder: "id",
            showClearButton: true,
            init: {
                value : "78"
            }
        },
    }]

Select Filter example (Single):

columns: [
    {
        label: "First Name",
        name: "name.first_name",
        filter: {
            type: "select",
            placeholder: "Select first name",
            options: [
                {
                    "name" : "Irwin",
                    "value" : "Irwin"
                },
                {
                    "name" : "Don",
                    "value" : "Don"
                },
                {
                    "name" : "Bessie",
                    "value" : "Bessie"
                }
            ],
            mode:"single",
            select_all_checkbox : {
                visibility: true,
                text: "Select all"
            },
            init: {
                value : 2
            }
        },
        sort: true,
        initial_sort: true, // "false" by default
    }
]

Select Filter example (Multi):

columns: [
    {
        label: "Last Name",
        name: "name.last_name",
        filter: {
            type: "select",
            placeholder: "Select last name",
            options: [
                {
                    "name" : "Irwin",
                    "value" : "Irwin"
                },
                {
                    "name" : "Don",
                    "value" : "Don"
                },
                {
                    "name" : "Bessie",
                    "value" : "Bessie"
                }
            ],
            mode:"multi",
            select_all_checkbox : {
                visibility: true,
                text: "Select all"
            },
            init: {
                value : [0,1]
            }
        },
        sort: true,
        initial_sort: true, // "false" by default
    }]

Global filter example:

config: {
    global_search: {
        placeholder: "Enter custom Search text",
        visibility: true,
        case_sensitive: false, // default false
        showClearButton: true,
        init: {
            value: "inital filter value"
        }
    }
}

Hope this works.

Cheers, Ruby.

sdrig commented 5 years ago

Hi @rubanraj54 ,

Filter init working but Custom filters like date-range, became invalid dates after upgrading 1.0.30

image

Thank you Sadri

rubanraj54 commented 5 years ago

Hi @sdrig

Since I have'nt finished implementing custom filter officially, I didn't consider custom filtering for this feature.

Probably, I will include the "custom" type filtering also in my next release.

And keep in mind that, I can only set the initial values to the queryParams but you have to manually update the initial value in your custom element since you have the control over it.

Cheers, Ruby.

sdrig commented 5 years ago

Hi @rubanraj54 , you are right. The issue was about model binding for custom filter. It's on the way now. Thanks again