-
Notifications
You must be signed in to change notification settings - Fork 192
feat: adds fuzzy search and adds serbian translation #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) { | ||||||
|
|
@@ -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 => { | ||||||
|
|
@@ -140,7 +165,7 @@ function getFilterMethod(rows, allData, filter) { | |||||
| return filterMethodMap[filter.type]; | ||||||
| } | ||||||
|
|
||||||
| function guessFilter(keyword = '') { | ||||||
| function guessFilter(keyword = '', data) { | ||||||
| if (keyword.length === 0) return {}; | ||||||
|
|
||||||
| let compareString = keyword; | ||||||
|
|
@@ -202,6 +227,20 @@ function guessFilter(keyword = '') { | |||||
| }; | ||||||
| } | ||||||
|
|
||||||
| const filterMatchStrategy = data && data.options && data.options.filterMatchStrategy; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||||||
|
|
||||||
| 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" | ||
| } | ||
| } |
There was a problem hiding this comment.
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
strategydirectly and set its default value to'strict'