zephyr_sdk/charting/
table.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use serde::Serialize;

#[derive(Serialize, Default)]
pub struct TableStyle {
    #[serde(rename = "font-size")]
    font_size: Option<String>,
}

#[derive(Serialize, Default)]
pub struct Style {
    table: TableStyle,
}

#[derive(Serialize, Default)]
pub struct Pagination {
    summary: bool,
    limit: i32,
}

#[derive(Serialize, Default)]
pub struct Table {
    columns: Vec<String>,
    data: Vec<Vec<String>>,
    style: Style,
    pagination: Pagination,
}

impl Table {
    pub fn new() -> Self {
        let mut new = Self::default();
        new.style.table.font_size = Some("12px".into());
        new.pagination.summary = true;
        new.pagination.limit = 10;

        new
    }

    pub fn columns(mut self, cols: Vec<String>) -> Self {
        self.columns = cols;
        self
    }

    pub fn row(mut self, row: Vec<String>) -> Self {
        self.data.push(row);
        self
    }
}