ng2-table icon indicating copy to clipboard operation
ng2-table copied to clipboard

match is not a function

Open lcborn4 opened this issue 9 years ago • 8 comments

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?

lcborn4 avatar Jan 20 '17 16:01 lcborn4

So im not sure why match function wasn't found but i found a workaround by using ==

return (item[column.name] === column.filtering.filterString);

lcborn4 avatar Jan 20 '17 16:01 lcborn4

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.

webcat12345 avatar Jan 30 '17 09:01 webcat12345

Can I know the function??

pranee1h avatar Feb 15 '17 16:02 pranee1h

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??

pranee1h avatar Feb 15 '17 19:02 pranee1h

With this return (item[column.name] === column.filtering.filterString); search is not working

pranee1h avatar Feb 15 '17 19:02 pranee1h

another if helped me:

if (item[column.name]){
            if (item[column.name].toString().match(this.config.filtering.filterString)) {
            flag = true;
            }
        }

noagr1 avatar Feb 20 '17 13:02 noagr1

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());

webcat12345 avatar Mar 28 '17 15:03 webcat12345

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

niskah-energies avatar Sep 29 '20 13:09 niskah-energies