Closed shahreyar-abeer closed 2 years ago
This is now possible with custom search methods in the latest development version (v0.2.3.9000):
- Column filtering and table searching can now be customized. Learn more in the Custom Filtering guide.
reactable()
gains asearchMethod
argument to use a custom JavaScript function for global table searching (#222).colDef()
gains afilterMethod
argument to use a custom JavaScript function for column filtering (#9, #90, #145).colDef()
gains afilterInput
argument to render a custom filter input for column filtering (#9).
There's no specific example of using multiple search strings, but there are a couple examples that might help with writing your own search method:
Here is a JS function I wrote for OR functionality in global search. It searches (case sensitive) for either one of the terms (separated by a space)
myFilterMethod <- JS('function(rows, columnIds, filterValue) {
// pattern defines a RegEx text based on the users input. In this users input, all occurences of spacebar are replaced by an OR sign.
//This is done so that if at least one his keywords is true, the row is displayed
// However, if the expression ends with an OR sign, the OR sign should be removed. If this is not done,
// then expressions ending in a spacebar will end in an OR sign and will always give true. This is what the second replace does.
const pattern = new RegExp(filterValue.replace(/ /g, "|").replace(/\\|$/, ""))
return rows.filter(function(row) {
return columnIds.some(function(columnId) {
return pattern.test(row.values[columnId])
// Use the pattern defined above to test the rows and return those that pass the pattern
})
})
}')
reactable(
data, searchable=TRUE,
searchMethod=myFilterMethod)
Is there a way to use multiple search strings in global search with an OR functionality?
For example, Search input: 'this that' Should match all instances of 'this' OR 'that'
I see a couple of solutions in the original package, but having a hard time integrating it with R