Skip to content

adds serbian translation and option to choose search type #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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -51,6 +51,7 @@ export default function getDefaultOptions(instance) {
// ColumnManager: CustomColumnManager
},
filterRows: filterRows,
filterMatchStrategy: 'strict', // strict, fuzzy, tokens
freezeMessage: '',
getEditor: null,
serialNoColumn: true,
43 changes: 41 additions & 2 deletions src/filterRows.js
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;
if (filterMatchStrategy === 'fuzzy' && keyword.includes(' ')) {
return {
type: 'fuzzy',
text: compareString.toLowerCase()
};
}
if (filterMatchStrategy === 'tokens' && keyword.includes(' ')) {
return {
type: 'tokens',
text: compareString.toLowerCase()
};
}

return {
type: 'contains',
text: compareString.toLowerCase()
2 changes: 2 additions & 0 deletions src/translations/index.js
Original file line number Diff line number Diff line change
@@ -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"
}
}