[RESOLVED] List/Library Data disappears when clearing search box

Hi,

I'm exploring the List/Library Control and it is amazing!

During my exploration, I came across something which I find really annoying. What I don't like is that the list/library data disappears when I clear the search box.

Is there anyway I can retrieve the original list data back to the way it was on form load?

I think the issue is pertaining to the search box filter. If it's empty its going to return nothing but is there no way to return this back to its original view dynamically?

Here is the code that I am using in my form to power the search box:

//Code will filter the List/Library Control based on Report_Type field
    var dt = fd.control('SPDataTable1');
    dt.ready(function() {
        filterDT();
    });

    //filter List or Library with new value when Search field changes
    fd.field('Search').$on('change', function() {
        filterDT();
    });

    function filterDT(){
        dt.filter = "<Contains><FieldRef Name='Report_Type'/><Value Type='Text'>"
            + fd.field('Search').value + "</Value></Contains>";
        dt.refresh();
    }

Dear @DryChips,
You can add a check to see if the Search field is empty, and then apply no filter, like this:

function filterDT(){
    if(fd.field('Search').value){
        dt.filter = "<Contains><FieldRef Name='Report_Type'/><Value Type='Text'>"
        + fd.field('Search').value + "</Value></Contains>";
    }
    else{
       dt.filter = ''; 
    }
    dt.refresh();
}
1 Like

Perfect, this is exactly what I was looking for!

Спасибо :grinning:

1 Like