1use ag_grid_core::convert::ToJsValue;
4use wasm_bindgen::prelude::*;
5use web_sys::HtmlElement;
6
7use crate::{column::ColumnApi, gridoptions::DataSource};
8
9pub struct Grid {
11 pub api: GridApi,
17 pub column_api: ColumnApi,
21}
22
23#[wasm_bindgen]
24extern "C" {
25 #[wasm_bindgen(js_name = Grid)]
26 pub(crate) type AgGrid;
27
28 #[wasm_bindgen(js_name = GridOptions)]
29 pub(crate) type AgGridOptions;
30
31 #[wasm_bindgen(constructor, js_namespace = agGrid, js_class = "Grid")]
32 pub(crate) fn new(eGridDiv: HtmlElement, gridOptions: JsValue) -> AgGrid;
33
34 #[wasm_bindgen(method, getter)]
35 pub(crate) fn gridOptions(this: &AgGrid) -> AgGridOptions;
36
37 #[wasm_bindgen(method, getter)]
38 pub(crate) fn api(this: &AgGridOptions) -> GridApi;
39
40 #[wasm_bindgen(method, getter)]
41 pub(crate) fn columnApi(this: &AgGridOptions) -> ColumnApi;
42}
43
44#[wasm_bindgen]
45extern "C" {
46 pub type GridApi;
50
51 #[wasm_bindgen(method)]
52 fn exportDataAsCsv(this: &GridApi);
53
54 #[wasm_bindgen(method)]
55 fn setRowData(this: &GridApi, data: JsValue);
56
57 #[wasm_bindgen(method)]
58 fn setDatasource(this: &GridApi, data_source: DataSource);
59}
60
61impl GridApi {
62 pub fn export_data_as_csv(&self) {
64 Self::exportDataAsCsv(self)
65 }
66
67 pub fn set_row_data<T>(&self, row_data: Vec<T>)
70 where
71 T: ToJsValue,
72 {
73 Self::setRowData(self, row_data.to_js_value())
74 }
75
76 pub fn set_data_source(&self, data_source: DataSource) {
79 Self::setDatasource(self, data_source)
80 }
81}