Search code examples
angularng2-smart-table

Filter using masks in n2-smart-table


I'm using Angular 6 with n2-smart-table. I want to search a string with and without mask on a filter.

Ex.: 28871154000178 and 28.871.154/0001-78 should return the same data.

enter image description here

I looked around various forums but was unable to find such a way.

Thanks in advance!


Solution

  • I found a way using filterFunction.

    Example:

    columns: {
        column {
            title: 'CPF/CNPJ',
            filterFunction(cell?: any, search?: string) {
                const match = cell.indexOf(search) > -1;
                const matchClean = cell.replace(/[^\d]+/g, '').indexOf(search) > -1;
                return (match || search === '') ? true : (matchClean) ? true : false;
            }
        }
    }