match is not a function
item[column.name].match is not a function
Has anybody gotten this error before?
return item[column.name].match(column.filtering.filterString);
is .match are javascript function?
So im not sure why match function wasn't found but i found a workaround by using ==
return (item[column.name] === column.filtering.filterString);
string.match() is javascript function. parameter is regex.
you will get that error, when null.match. so You need to convert all undefined or null to ''(emptyString).
Additionally regex syntax will now allow |\/[](). You need to make new function for this case.
Can I know the function??
I am trying to fix by adding if conditionif (column.filtering) { filteredData = filteredData.filter((item:any) => { if(item[column.name] === null){ item[column.name] = ""; } return item[column.name].match(column.filtering.filterString); }); } but it's not working. Can someone post the solution??
With this return (item[column.name] === column.filtering.filterString); search is not working
another if helped me:
if (item[column.name]){
if (item[column.name].toString().match(this.config.filtering.filterString)) {
flag = true;
}
}
data shouldn't contain nullstring. This is the first case.
Before drawing table you need to convert null to ''(empty string). Second is regex.
convertSpecialCharacter(str:string):string {
const regex = /\/|\\|\(|\)|\[|\]|\|/g;
let m;
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
str = str.substr(0, m.index) + '\\' + str.substr(m.index);
regex.lastIndex++;
}
return str;
}
return item[column.name].toLowerCase().match(this.publicService.convertSpecialCharacter(column.filtering.filterString).toLowerCase());
I have the same error, but don't know why. filterString is not undefined, it's an empty string but item[column.name] is an integer, maybe it's the problem