Skip to main content

Crate datagrid_export

Crate datagrid_export 

Source
Expand description

Writes what a grid shows as a file.

The table comes from datagrid_core::export_table, which takes the visible columns in the order the grid lays them out and the rows as sorted, filtered and grouped. This crate only writes it: each format is a feature, so that the ones with heavy dependencies cost nothing to anyone who does not ask for them. CSV needs no dependency at all.

use datagrid_core::{
    CellValue, ColumnSpec, ExportScope, GridLocale, GridState, export_table,
};
use datagrid_export::{CsvOptions, to_csv};

struct Person {
    name: &'static str,
    age: i64,
}

let rows = [Person { name: "Zoe", age: 31 }, Person { name: "Adi", age: 27 }];
let columns = [
    ColumnSpec::new("name").value(|row: &Person| CellValue::Text(row.name)),
    ColumnSpec::new("age").value(|row: &Person| CellValue::Int(row.age)),
];
let table = export_table(
    &rows,
    &columns,
    |id| id.as_str().to_owned(),
    &GridState::new(),
    &GridLocale::english(),
    ExportScope::Filtered,
);

assert_eq!(to_csv(&table, &CsvOptions::default()), "name,age\r\nZoe,31\r\nAdi,27\r\n");

Structs§

CsvOptions
How to_csv writes.
HtmlOptions
How to_html writes.

Enums§

CsvValues
What the cells say.
LineEnding
How a line ends.

Constants§

PRINT_CSS
The rules a document needs to print well: the header repeats on every page, a row stays whole, numbers line up.

Functions§

to_csv
Writes the table as CSV.
to_html
Writes the table as HTML.