working on improving component loading

This commit is contained in:
2026-01-10 19:17:17 +01:00
parent 797883dac8
commit 5201858b79
5 changed files with 104 additions and 9 deletions

View File

@@ -12,6 +12,8 @@ from myfasthtml.core.constants import ColumnType, ROW_INDEX_ID, FooterAggregatio
from myfasthtml.core.dbmanager import DbObject
from myfasthtml.core.instances import MultipleInstance
from myfasthtml.core.utils import make_safe_id
from myfasthtml.icons.fluent import checkbox_unchecked16_regular
from myfasthtml.icons.fluent_p2 import checkbox_checked16_regular
class DatagridState(DbObject):
@@ -149,7 +151,7 @@ class DataGrid(MultipleInstance):
def mk_body_cell_content(self, col_pos, row_index, col_def: DataGridColumnState):
def mk_bool(_value):
return Div(mk.icon(icon_checked if _value else icon_unchecked, can_select=False),
return Div(mk.icon(checkbox_checked16_regular if _value else checkbox_unchecked16_regular, can_select=False),
cls="dt2-cell-content-checkbox")
def mk_text(_value):
@@ -301,7 +303,7 @@ class DataGrid(MultipleInstance):
else:
value = None
return Div(mk_ellipsis(value, cls="dt2-cell-content-number"),
return Div(mk.label(value, cls="dt2-cell-content-number"),
data_col=col_def.col_id,
style=f"width:{col_def.width}px;",
cls="dt2-cell dt2-footer-cell",

View File

@@ -115,11 +115,18 @@ class TabsManager(MultipleInstance):
def _dynamic_get_content(self, tab_id):
if tab_id not in self._state.tabs:
return Div("Tab not found.")
tab_config = self._state.tabs[tab_id]
if tab_config["component"] is None:
return Div("Tab content does not support serialization.")
res = InstancesManager.get(self._session, tab_config["component"][1], None)
if res is not None:
return res
try:
return InstancesManager.get(self._session, tab_config["component"][1])
logger.debug(f"Component not created yet. Need to manually create it.")
return InstancesManager.dynamic_get(self._session, tab_config["component_parent"], tab_config["component"])
except Exception as e:
logger.error(f"Error while retrieving tab content: {e}")
return Div("Failed to retrieve tab content.")