ag_grid_rs/
lib.rs

1//! Rust bindings for the [`AG Grid`] JavaScript library.
2//!
3//! With this crate, one is able to use the AG Grid datatable library within a
4//! Wasm context in Rust.
5//!
6//! A simple example demonstrating server-side data fetching using `Yew` and
7//! related dependencies is as follows:
8//!
9//! ```rust
10//! use ag_grid_rs::{
11//!     gridoptions::{DataSourceBuilder, RowModelType},
12//!     ColumnDef, GridOptions, ToJsValue,
13//! };
14//! use gloo_net::http::Request;
15//! use serde::Deserialize;
16//! use wasm_bindgen::JsCast;
17//! use web_sys::HtmlElement;
18//! use yew::prelude::*;
19//!
20//! #[function_component(About)]
21//! pub fn about() -> Html {
22//!     use_effect_with_deps(
23//!         |_| {
24//!             // Get the element to which you want to attach the grid
25//!             let grid_div = get_element_by_id("grid-div");
26//!
27//!             // Define your columns
28//!             let field_names = vec!["athlete", "age", "country", "year"];
29//!             let cols = field_names
30//!                 .iter()
31//!                 .map(|name| ColumnDef::new(name).sortable(true))
32//!                 .collect();
33//!
34//!             // Create your datasource, including a closure that will retunr rows from the
35//!             // server
36//!             let data_source = DataSourceBuilder::new(|params| async move {
37//!                 // `params` contains information from AG Grid about which rows to get, how to
38//!                 // sort the data, etc
39//!                 let data_url = "https://www.ag-grid.com/example-assets/olympic-winners.json";
40//!                 let rows = gloo_net::http::Request::get(data_url)
41//!                     .send()
42//!                     .await?
43//!                     .json::<Vec<JsonData>>()
44//!                     .await?;
45//!
46//!                 Ok((rows, None))
47//!             })
48//!             .build();
49//!
50//!             let grid = GridOptions::<JsonData>::new()
51//!                 .column_defs(cols)
52//!                 .row_model_type(RowModelType::Infinite)
53//!                 .datasource(data_source)
54//!                 .build(grid_div);
55//!
56//!             // `grid` now provides a handle to the grid and column APIs
57//!             || ()
58//!         },
59//!         (),
60//!     );
61//!
62//!     html! {
63//!         <>
64//!             <div id="grid-div" class="ag-theme-alpine" style="height: 500px"/>
65//!         </>
66//!     }
67//! }
68//!
69//! #[derive(ToJsValue, Deserialize)]
70//! struct JsonData {
71//!     athlete: String,
72//!     age: Option<usize>,
73//!     country: String,
74//!     year: usize,
75//! }
76//!
77//! fn get_element_by_id(id: &str) -> HtmlElement {
78//!     web_sys::window()
79//!         .expect("unable to get window object")
80//!         .document()
81//!         .expect("unable to get document object")
82//!         .get_element_by_id(id)
83//!         .expect("unable to find grid-div")
84//!         .dyn_into::<HtmlElement>()
85//!         .unwrap()
86//! }
87//! ```
88//!
89//! [`AG Grid`]: https://www.ag-grid.com/javascript-data-grid/
90
91pub mod callbacks;
92pub mod column;
93pub mod filter;
94pub mod grid;
95pub mod gridoptions;
96mod shared;
97pub mod sort;
98#[doc(hidden)]
99mod types;
100
101pub use ag_grid_core::convert;
102#[doc(hidden)]
103pub use ag_grid_core::imports;
104pub use ag_grid_derive::ToJsValue;
105pub use column::{ColumnApi, ColumnDef};
106pub use grid::{Grid, GridApi};
107pub use gridoptions::GridOptions;