from reactable import Reactable, Column, JS, embed_css
from reactable.data import cars_93, penguins
import polars as pl
embed_css()
= penguins.to_polars()
pl_penguins
= cars_93[:20, ["manufacturer", "model", "type", "air_bags", "price"]] cars
Filtering
You can make columns filterable by setting filterable=True
:
Reactable(
cars,=True,
filterable=10,
min_rows )
To make specific columns filterable (or not), set filterable in Column()
:
Reactable(
cars,=True,
filterable=[Column(id="price", filterable=False)],
columns=5,
default_page_size )
Custom filtering
Column filtering can be customized using the filter_method
and filter_input
arguments in Column()
. See the Custom Filtering guide for more details and examples. (TODO)
This example shows basic usage of a custom filter method, changing filtering on the "manufacturer"
column to be case-sensitive rather than case-insensitive. (Try filtering for “bmw” and then “BMW”).
= pl_penguins.with_columns(pl.col("species").str.to_titlecase())
titled
= JS(
js_filter """
function(rows, columnId, filterValue) {
return rows.filter(function(row) {
return row.values[columnId].indexOf(filterValue) !== -1
})
}"""
)
Reactable(=titled.head(2),
data=True,
filterable={
columns"manufacturer": Column(filter_method=js_filter),
},=5,
default_page_size )