My question is the following. I am trying to create a reactable with R, and I basically want the search bar to be able to global search for multiple strings separated by a whitespace; so for example, I want to be able to insert in the search bar the following: “FOO BAR”, and be able to get all the rows that contains (in every order, and in every column) both FOO, and BAR; the terms does not need to be in the same column, but need to be in the same row.
I am struggling to do so; I am following several examples online and found this online: https://github.com/glin/reactable/issues/222 in which a user propose a method (see code below from that question on github) that actually works well concatenating different string with an OR.
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)
How can I create a similar thing but concatenating string with AND instead that with OR?