How to display a warning if a filter (search) is applied by Yadcf?

How to display a warning if a filter (search) is applied by Yadcf?

lenamtllenamtl Posts: 265Questions: 65Answers: 1
edited December 2017 in Free community support

Hi,

All my Yadcf filters are in a collapsable box.
When the box is collapsed we don't see if there are filters set.
So I'm looking for a way to display a warning on the page if any filters is applied by Yadcf.

The only way I see is to get info from localstorage but this is complicated to parse...

Any other way to do it?

Thanks

Answers

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    This is checking for Yadfc filter and Datatable on search.

    table24.on('search.dt', function() {
            
                    // check datatables search
                     if (table24.search(this.value) != "") {
                $('#myfilter1').addClass('alert alert-warning').html('There is a search item');
                } else {  
                $("#myfilter1").removeClass('alert alert-warning').html('There is no search item');
                }
                    // check yadcf filters 
            if (yadcf.exGetColumnFilterVal(table24, 2) != "") {
                $('#myfilter2').addClass('alert alert-warning').html('There is filter applied');
                } else {  
                $("#myfilter2").removeClass('alert alert-warning').html('There is no filter applied');
                }
    
    });
    

    I will also add the code for on page load...

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Note, this is not checking from localstorage, only from field values.

    This can cause an issue in multi-language environment so it is better to check from localstorage when it is enable.

    I will post the link when I will get it working.

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    most of yadcf filters when used got the inuse class... so you might wanna use it to apply a special styling to a filter that got the inuse class

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Hi Daniel

    I'm looking for a way to parse the info from the savestate localstorage value
    How can I parse this from Yadcf ?
    "yadcfState":{"-allmytasks-list":[null,null,null,null,null,{"from":"01/03/2018","to":"24/03/2018"}

    The problem that may occurred if you only get the info from the field is the following
    Let say I select a filter value from a dropdown then I get a result

    Later I come back to the page the value I uses for the search is no more more available from the dropdown (for any good reason not a bug) at this point the search value is still saved in localstorage, and the field is now empty, this can cause a confusion to the user and he may think there is no filter applied as in fact there is.

    Same problem in multi-language if a user switch from a language to another ....

    So this is why relying on field value only is not a good idea.

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    When using state saving in datatables your value should be there when you leave/refresh page

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited March 2018

    yes but now I have to parse theses values from localstorage datatabase
    Similare to this
    https://datatables.net/forums/discussion/48280/how-to-parse-statesave-values

    but from Yadcf part
    "yadcfState":{"-allmytasks-list":[null,null,null,null,null,{"from":"01/03/2018","to":"24/03/2018"}

This discussion has been closed.