Skip to main content

actix_web_admin/types/
column.rs

1/// Type of data displayed in a table column.
2#[derive(Debug, Clone, Copy, serde::Serialize)]
3pub enum ColumnType {
4    Text,
5    Number,
6    Boolean,
7    Date,
8}
9
10/// Configuration for a column in the admin list view.
11#[derive(Debug, Clone, serde::Serialize)]
12pub struct Column {
13    pub key: String,
14    pub label: String,
15    pub sortable: bool,
16    pub column_type: ColumnType,
17}
18
19impl Column {
20    pub fn text(key: &str, label: &str) -> Self {
21        Self {
22            key: key.to_string(),
23            label: label.to_string(),
24            sortable: true,
25            column_type: ColumnType::Text,
26        }
27    }
28
29    pub fn number(key: &str, label: &str) -> Self {
30        Self {
31            key: key.to_string(),
32            label: label.to_string(),
33            sortable: true,
34            column_type: ColumnType::Number,
35        }
36    }
37
38    pub fn boolean(key: &str, label: &str) -> Self {
39        Self {
40            key: key.to_string(),
41            label: label.to_string(),
42            sortable: true,
43            column_type: ColumnType::Boolean,
44        }
45    }
46
47    pub fn date(key: &str, label: &str) -> Self {
48        Self {
49            key: key.to_string(),
50            label: label.to_string(),
51            sortable: true,
52            column_type: ColumnType::Date,
53        }
54    }
55}