Skip to content

Commit

Permalink
addressing issue #307
Browse files Browse the repository at this point in the history
adding global fuzzy string matching to table search
  • Loading branch information
nhall6 committed Aug 15, 2024
1 parent 4483c72 commit a0057cc
Showing 1 changed file with 43 additions and 25 deletions.
68 changes: 43 additions & 25 deletions R/components-data-viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ function filterMinValue(rows, columnId, filterValue) {
});
}
"
#use fuzzy text matching for global table search
fuzzySearch<- htmlwidgets::JS('function(rows, columnIds, filterValue) {
// Create a case-insensitive RegEx pattern that performs a fuzzy search.
const pattern = new RegExp(filterValue, "i");
return rows.filter(function(row) {
return columnIds.some(function(columnId) {
return pattern.test(row.values[columnId]);
});
});
}')

output$resultData <- reactable::renderReactable({
if (is.null(input$dataCols)) {
data = newdf()
Expand All @@ -351,31 +364,36 @@ function filterMinValue(rows, columnId, filterValue) {
} else{
height <- NULL
}

reactable::reactable(
data,
columns = colDefs(),
onClick = onClick,
groupBy = groupBy,
#these can be turned on/off and will overwrite colDef args
sortable = TRUE,
resizable = TRUE,
filterable = TRUE,
searchable = TRUE,
showPageSizeOptions = TRUE,
outlined = TRUE,
showSortIcon = TRUE,
striped = TRUE,
highlight = TRUE,
#defaultColDef = reactable::colDef(align = "left"),
defaultSorted = sortedColumns(),
rowStyle = list(
height = height
),
elementId = elementIdName()
#, experimental
#theme = ohdsiReactableTheme
)
# htmltools::browsable(
# tagList(
# matchSorterDep,
reactable::reactable(
data,
columns = colDefs(),
onClick = onClick,
groupBy = groupBy,
#these can be turned on/off and will overwrite colDef args
sortable = TRUE,
resizable = TRUE,
filterable = TRUE,
searchable = TRUE,
searchMethod = fuzzySearch,
showPageSizeOptions = TRUE,
outlined = TRUE,
showSortIcon = TRUE,
striped = TRUE,
highlight = TRUE,
#defaultColDef = reactable::colDef(align = "left"),
defaultSorted = sortedColumns(),
rowStyle = list(
height = height
),
elementId = elementIdName()
#, experimental
#theme = ohdsiReactableTheme
)
# )
# )
})


Expand Down

0 comments on commit a0057cc

Please sign in to comment.