orbital-datatable 0.1.1

Interactive DataTable product for the Orbital component library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use leptos::prelude::Callable;
use orbital_data::DataValue;

use crate::types::{DataTableColumnDef, DataTableRowModel};

pub fn resolve_value(col: &DataTableColumnDef, row: &DataTableRowModel) -> DataValue {
    if let Some(resolver) = &col.resolve_value {
        return resolver.run((row.record.clone(),));
    }
    row.get(&col.field).cloned().unwrap_or(DataValue::Null)
}

pub fn format_display(col: &DataTableColumnDef, value: &DataValue) -> String {
    if let Some(formatter) = &col.format_display {
        return formatter.run((value.clone(),));
    }
    value.display_string()
}