Filtering with JQuery

0

I have this statement in JQuery to filter JSON data

 var datos = $(Data).filter(function (index, value) {

            return value.Apellido == Apellido;
    });

Where Data is my data concentrate, I want to filter those with a last name X, I do it correctly, but only if the last name I give is strictly the same as it is in the table, that is, it is not same "Hernández" to "Hernández". Is there any way to make a LIKE type like in SQL?

    
asked by EriK 06.11.2017 в 17:45
source

1 answer

2

You can complicate it as much as you want.

For example:

var datos = $(Data).filter(function (index, value) {
  return value.Apellido.toUpperCase().indexOf(Apellido.toUpperCase()) >= 0;
});

It would be what a LIKE '%XXXX%' in SQL, without differentiating between uppercase and lowercase. Another option is to use regular expressions, but the first thing you have to be clear about is what rules you want to apply to the search.

    
answered by 06.11.2017 / 17:57
source