From: Andrea Zagli Date: Mon, 2 Jan 2023 16:25:45 +0000 (+0100) Subject: Method get_column. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=70df3d038576892a6739058d39688bca12fc4fd3;p=rust%2Fzakgrid Method get_column. --- diff --git a/examples/grid.rs b/examples/grid.rs index ba287d8..d1f6189 100644 --- a/examples/grid.rs +++ b/examples/grid.rs @@ -63,6 +63,9 @@ async fn index( col.set_title("the second column title"); grid.add_column(col); + let mut col = grid.get_column("col2 name").unwrap(); + col.set_align(zakgrid::Align::Right); + let cols = grid.columns(); for (i, v) in cols.iter().enumerate() { diff --git a/src/lib.rs b/src/lib.rs index 8025e2a..7088ef4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,6 +97,16 @@ impl Grid { &self.columns } + pub fn get_column(&mut self, column_name: &str) -> Result<&mut Column, ()> { + for c in &mut self.columns { + if c.name.as_str() == column_name { + return Ok(c); + } + } + + Err(()) + } + pub fn header(&self) -> String { let mut s = String::new();