Skip to content

Commit

Permalink
Update OJS example to use setFilter instead of setData
Browse files Browse the repository at this point in the history
  • Loading branch information
glin committed Feb 4, 2024
1 parent 1677182 commit ad8fffc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions vignettes/quarto/observable-reactable.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ viewof islands = Inputs.checkbox(
//| include: false
data = FileAttachment("palmer-penguins.csv").csv({ typed: true })
filtered = data.filter(penguin => {
return penguin.bill_length > billLengthMin && islands.includes(penguin.island)
})
// Update table data when filtered data changes
Reactable.setData('tbl', filtered)
// Update table filters when filtered data changes
Reactable.setFilter('tbl', 'bill_length', billLengthMin)
Reactable.setFilter('tbl', 'island', islands)
```

```{r}
Expand All @@ -52,6 +49,18 @@ reactable(
wrap = FALSE,
resizable = TRUE,
minRows = 10,
columns = list(
bill_length = colDef(
filterMethod = JS("(rows, columnId, billLengthMin) => {
return rows.filter(row => row.values[columnId] > billLengthMin)
}")
),
island = colDef(
filterMethod = JS("(rows, columnId, islands) => {
return rows.filter(row => islands.includes(row.values[columnId]))
}")
)
),
elementId = "tbl"
)
```
Expand Down

0 comments on commit ad8fffc

Please sign in to comment.