From 70df3d038576892a6739058d39688bca12fc4fd3 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 2 Jan 2023 17:25:45 +0100 Subject: [PATCH] Method get_column. --- examples/grid.rs | 3 +++ src/lib.rs | 10 ++++++++++ 2 files changed, 13 insertions(+) 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(); -- 2.49.0