Filter on Text Field but keep List Items

Hey there!

how can i filter in List Controll but keep the Items as long as nothing is written in the search field.

i use this code:

d.spRendered(function() {
    var dt = fd.control('SPDataTable0');
    dt.ready(function() {
        filterDT();
    });

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

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

  1. when empty, than the lookup data is also empty:

Hi @TomRischkau,

I suggest checking if the search field is empty and removing the filter if it is. Try this:

fd.spRendered(function() {
    var dt = fd.control('SPDataTable0');
    dt.ready(function() {
        filterDT();
    });

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

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

Hi @IliaLazarevskii

Thank you!
but its working only when i type something in the search field and erase it.

it would be perfect when the List data is also visiable when some opens the form.

i recorded a quick video:
Video

Hi @TomRischkau,

I couldn't reproduce this behavior. Is there any code on the form other than the snippet you've shared?

Regardless, clearing the search field before filtering the control for the first time could help:

dt.ready(function() {
    fd.field('Suchen').value = '';
    filterDT();
});

Let me know how it goes.

@IliaLazarevskii

Yep!
Thats it! Working fine.