tests/test-ci/test-filter-api-js.R

# External filter controller: el._lt.filter() for outside widgets (browser).

assert("el._lt.filter lets outside widgets filter the table, composing with AND", {
  # forestly drives the table through this controller, not the built-in boxes
  x = itbl(pager = FALSE)
  rows = 't.querySelectorAll("tbody tr").length'
  (lti_eval(x, rows) %==% '4')
  # a predicate over the row's raw values (keyed by column) keeps matching rows
  big = 't._lt.filter("big", row => row.n > 5)'
  (lti_eval(x, rows, big) %==% '2')
  # a second predicate under another id composes with AND
  both = paste(big, 't._lt.filter("nm", row => row.name !== "Nausea")', sep = ';')
  (lti_eval(x, rows, both) %==% '1')
  # a null fn removes just that one predicate
  (lti_eval(x, rows, paste(both, 't._lt.filter("big", null)', sep = ';')) %==% '3')
  # a predicate survives a re-render (here, sorting a column)
  sortN = paste(big,
    'document.querySelector("thead th .lti-label").click()', sep = ';')
  (lti_eval(x, rows, sortN) %==% '2')
})

assert("external predicates see hidden columns too (not just the visible ones)", {
  # forestly filters on hidden helper columns; predicate rows must carry them
  x = lt(data.frame(name = sym, n = c(5, 12, 3, 8), g = c("a", "b", "a", "b"))) |>
    lt_hide("g") |> lt_interactive(pager = FALSE)
  rows = 't.querySelectorAll("tbody tr").length'
  (lti_eval(x, rows, 't._lt.filter("g", row => row.g === "a")') %==% '2')
})

Try the lt package in your browser

Any scripts or data that you put into this service are public.

lt documentation built on Oct. 17, 2026, 9:06 a.m.