Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function getDefaultOptions(instance) {
// ColumnManager: CustomColumnManager
},
filterRows: filterRows,
filterMatchStrategy: 'strict', // strict, fuzzy, tokens
freezeMessage: '',
getEditor: null,
serialNoColumn: true,
Expand Down
43 changes: 41 additions & 2 deletions src/filterRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function filterRows(rows, filters, data) {

const cells = filteredRows.map(row => row[colIndex]);

let filter = guessFilter(keyword);
let filter = guessFilter(keyword, data);
let filterMethod = getFilterMethod(rows, data, filter);

if (filterMethod) {
Expand Down Expand Up @@ -76,6 +76,31 @@ function getFilterMethod(rows, allData, filter) {
.map(cell => cell.rowIndex);
},

fuzzy(keyword, cells) {
const terms = keyword.split(/\s+/).filter(term => term.length > 0);
return cells
.filter(cell => {
if (terms.length === 0) return true;
const cellValue = stringCompareValue(cell);
return terms.every(term => cellValue.includes(term));
})
.map(cell => cell.rowIndex);
},

tokens(keyword, cells) {
const terms = keyword.split(/\s+/).filter(term => term.length > 0);
return cells
.filter(cell => {
if (terms.length === 0) return true;
const cellValue = stringCompareValue(cell);
return terms.every(term => {
const regex = new RegExp(`\\b${term}\\b`, 'i');
return regex.test(cellValue);
});
})
.map(cell => cell.rowIndex);
},

greaterThan(keyword, cells) {
return cells
.filter(cell => {
Expand Down Expand Up @@ -140,7 +165,7 @@ function getFilterMethod(rows, allData, filter) {
return filterMethodMap[filter.type];
}

function guessFilter(keyword = '') {
function guessFilter(keyword = '', data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only the strategy is used here, then in my opinion, there's no need to pass the whole data object — you can just pass the strategy directly and set its default value to 'strict'

if (keyword.length === 0) return {};

let compareString = keyword;
Expand Down Expand Up @@ -202,6 +227,20 @@ function guessFilter(keyword = '') {
};
}

const filterMatchStrategy = data && data.options && data.options.filterMatchStrategy;
Copy link
Member

@iamejaaz iamejaaz Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const filterMatchStrategy = data && data.options && data.options.filterMatchStrategy;
const filterMatchStrategy = data?.options?.filterMatchStrategy';

if (filterMatchStrategy === 'fuzzy' && keyword.includes(' ')) {
return {
type: 'fuzzy',
text: compareString.toLowerCase()
};
}
if (filterMatchStrategy === 'tokens' && keyword.includes(' ')) {
return {
type: 'tokens',
text: compareString.toLowerCase()
};
}
Comment on lines +231 to +242
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between this and the return statement below is the type value. You could simplify the logic by assigning the type to a variable and defaulting it to 'contains'.


return {
type: 'contains',
text: compareString.toLowerCase()
Expand Down
2 changes: 2 additions & 0 deletions src/translations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import en from './en.json';
import de from './de.json';
import fr from './fr.json';
import it from './it.json';
import sr from './sr.json';

export default function getTranslations() {
return {
en,
de,
fr,
it,
sr,
};
};
15 changes: 15 additions & 0 deletions src/translations/sr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Sort Ascending": "Sortiraj rastući",
"Sort Descending": "Sortiraj opadajući",
"Reset sorting": "Resetuj sortiranje",
"Remove column": "Ukloni kolonu",
"No Data": "Nema podataka",
"{count} cells copied": {
"1": "{count} polje kopirano",
"default": "{count} polja kopirano"
},
"{count} rows selected": {
"1": "{count} red izabran",
"default": "{count} redova izabrano"
}
}