0

I am implementing a filter search for my search box, everything works well the array get filtered as i need, but it has a strange behaviour, since the search is almost at the bottom of the page (the scrool is at the bottom too) when i enter a character to search on the searchbox the scrool go up i think th ebehaviour has nothing to do with css, the problem is with my filter function.

I do it this way:

public onSearchChange(nameSearch: string): void {
    if (this.myFullArr) {
        const search = nameSearch.toLowerCase();
        this.myArr = this.myFullArr.filter((element) => {
            if (element.Name.toLowerCase().indexOf(search) !== -1) {
                return true;
            }
            return false;
        })
    }
}

this function is called when my search box change, as you guys can see the myFullArr is the initial contend that is static and doesn't change, since i can't use just the original array because it will change, the myArr is the filtered array.

Any help?

Thanks

Tazbirul Haque
  • 233
  • 1
  • 3
  • 15
Filipe Costa
  • 159
  • 1
  • 2
  • 8

1 Answers1

0

Try calling your onSearchChange function as follows.

    <input id="text" type="text" />

    the function

    document.getElementById('text').onkeydown = new function(event){
    onSearchChange("your search text")
    return false
}

You can get an idea from this question as well.

Channa
  • 3,267
  • 7
  • 41
  • 67