Tables

SimStack II provides a SimpleTable model to handle and display tabular data, especially for UI representation in ag-grid.

SimpleTable

The SimpleTable model allows you to define a table with headings, data types for columns, and rows of data.

Key Features:

  • UI Ready: Designed to be used with a specialized UI field (SimpleTableField) that renders the data in an ag-grid component.

  • Flexible Rows: Rows are stored as dictionaries, making it easy to map data to column headers.

  • Type Information: Allows specifying the type of each column for better UI rendering or validation.

Usage:

from simstack.models.simple_table import SimpleTable

table = SimpleTable(name="Experimental Results")

# Add columns with their types
table.add_column("Material", "string")
table.add_column("Temperature", "number")
table.add_column("Pressure", "number")

# Add rows as dictionaries
table.add_row({
    "Material": "Silicon",
    "Temperature": 300,
    "Pressure": 1.0
})
table.add_row({
    "Material": "Germanium",
    "Temperature": 350,
    "Pressure": 1.2
})

API Reference

class simstack.models.simple_table.SimpleTable(*, name: str = 'SimpleTable', heading: list[str] = <factory>, row: list[dict[str, ~typing.Any]]=<factory>, type: list[SimpleTableColumnType] = <factory>, id: ObjectId = <factory>)[source]

Bases: Model

A simple table model to display tabular data using ag-grid

add_column(column_name: str, column_type: SimpleTableColumnType | str) None[source]
add_row(row: Dict[str, Any]) None[source]
async custom_model_dump(**kwargs) Dict[str, Any]

Custom model dump method to handle the conversion of model instances to dictionaries. This method recursively traverses dictionaries and lists to convert any nested model instances to their dictionary representation.

Parameters:
  • self – The model instance

  • kwargs – Additional keyword arguments

Returns:

A dictionary representation of the model instance

classmethod from_dict(data: dict, **kwargs) Any

Create an instance of the model from a dictionary. Handles nested models and enum values.

classmethod from_model(model: Model, **kwargs) Model
heading: list[str] = <odmantic.field.FieldProxy object>
id: ObjectId = <odmantic.field.FieldProxy object>
classmethod json_schema()

Generates a JSON schema for the given class and its fields, but eliminates all fields which are models, embedded models, or references to models.

Parameters:

cls

Returns:

model_config = {'arbitrary_types_allowed': False, 'collection': None, 'extra': None, 'indexes': None, 'json_schema_extra': None, 'parse_doc_with_default_factories': False, 'str_strip_whitespace': False, 'title': None, 'validate_assignment': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str = <odmantic.field.FieldProxy object>
classmethod normalize_column_types(value: Any) Any[source]
row: list[dict[str, Any]] = <odmantic.field.FieldProxy object>
type: list[SimpleTableColumnType] = <odmantic.field.FieldProxy object>
classmethod ui_make_title(ui_schema: Dict[str, Any], field: str, title: str) dict

Adds a title to the JSON schema.

Parameters:
  • cls – The class to which the JSON schema belongs

  • ui_schema – The original ui_schema schema

  • title – Title to be added

Returns:

Modified JSON schema with title

classmethod ui_schema() Dict[str, str][source]