function wordFilter(headerValue, rowValue) { if (!headerValue) { return true; // If no…
- User
function wordFilter(headerValue, rowValue) { if (!headerValue) { return true; // If no input, show all rows }
// Split the input into words, normalize to lowercase const words = headerValue.toLowerCase().split(/\s+/); const cellValue = rowValue.toString().toLowerCase(); // Normalize cell value // Check if all words in the input exist in the cell value return words.every(word => cellValue.includes(word));}
make hightlight word match
- Assistant
To highlight the words that match in the based on the input , you can modify the function to return the modified where the matching words are wrapped in a tag with a specific style for highlighting.
- User
// Custom filter function to filter by words in the "Topic" column function wordFilter(headerValue, rowValue) { if (!headerValue) { return true; // If no input, show all rows }
// Split the input into words, normalize to lowercase const words = headerValue.toLowerCase().split(/\s+/); const cellValue = rowValue.toString().toLowerCase(); // Normalize cell value const pattern = new RegExp(`(${words.join('|')})`, 'gi'); // Check if all words in the input exist in the cell value return words.every(word => cellValue.includes(word)); const highlightedRowValue = rowValue.toString().replace(pattern, '<span style="background-color: yellow;">$1</span>'); return highlightedRowValue;}
no hightlight matched word
- Assistant