Skip to main content

DataTable

Struct DataTable 

Source
pub struct DataTable { /* private fields */ }
Expand description

A scrollable data table widget with columns and rows.

Supports keyboard navigation, row selection, and both vertical and horizontal scrolling.

Implementations§

Source§

impl DataTable

Source

pub fn new(columns: Vec<Column>) -> Self

Create a new data table with the given columns.

Source

pub fn with_header_style(self, style: Style) -> Self

Set the header style.

Source

pub fn with_row_style(self, style: Style) -> Self

Set the row style.

Source

pub fn with_selected_style(self, style: Style) -> Self

Set the selected row style.

Source

pub fn with_border(self, border: BorderStyle) -> Self

Set the border style.

Source

pub fn push_row(&mut self, row: Vec<String>)

Add a row of data.

Source

pub fn set_rows(&mut self, rows: Vec<Vec<String>>)

Set all rows at once, resetting selection.

Source

pub fn row_count(&self) -> usize

Get the number of rows.

Source

pub fn column_count(&self) -> usize

Get the number of columns.

Source

pub fn selected_row(&self) -> usize

Get the selected row index.

Source

pub fn set_selected_row(&mut self, idx: usize)

Set the selected row (clamped to valid range).

Source

pub fn selected_row_data(&self) -> Option<&[String]>

Get the data for the selected row.

Source

pub fn columns(&self) -> &[Column]

Get the column definitions.

Source

pub fn col_offset(&self) -> u16

Get the horizontal scroll offset.

Source

pub fn with_resizable_columns(self, enabled: bool) -> Self

Enable column resizing.

Source

pub fn sort_by_column(&mut self, col_idx: usize)

Sort by the given column index (toggle ascending/descending).

First call sorts ascending; repeated calls on the same column toggle direction.

Source

pub fn clear_sort(&mut self)

Clear the sort and restore original order.

Source

pub fn sort_state(&self) -> Option<(usize, bool)>

Get the current sort state: (column_index, ascending).

Source

pub fn set_column_width(&mut self, col_idx: usize, width: u16)

Set the width of a column by index.

Source

pub fn column_width(&self, col_idx: usize) -> Option<u16>

Get the width of a column by index.

Trait Implementations§

Source§

impl InteractiveWidget for DataTable

Source§

fn handle_event(&mut self, event: &Event) -> EventResult

Handle an input event. Returns whether the event was consumed.
Source§

impl Widget for DataTable

Source§

fn render(&self, area: Rect, buf: &mut ScreenBuffer)

Render this widget into the given area of the buffer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.