docs/enterprise/ag_grid/model-wrapper.md
A model wrapper is an utility used to wrap a database model and provide a consistent interface over it. It allows automatically adding new rows to the database, updating existing rows, and deleting rows.
You can use the basic functionality of the model wrapper by using the rxe.model_wrapper function. This function takes a database model and returns a wrapper object that can be used to interact with the model.
import reflex_enterprise as rxe
def index_page():
return rxe.model_wrapper(class_model=MyModel)
By default the model_wrapper use the infinite rows model from AgGrid.
If the default model wrapper does not fit your needs, you can create a custom model wrapper by subclassing the rxe.ModelWrapper class. This allows you to customize the behavior of the model wrapper to fit your specific use case.
import reflex_enterprise as rxe
class MyCustomWrapper(rxe.ModelWrapper[MyModel]):
pass
In the custom model wrapper, you can override the following methods:
_get_columns_defs_get_data_row_counton_value_setterto modify how the model wrapper will behave.
The SSRM model wrapper, used with rxe.model_wrapper_ssrm, is a version of the model wrapper that allows you to use the ServerSideRowModel of AgGrid.
import reflex_enterprise as rxe
def index_page():
return rxe.model_wrapper_ssrm(class_model=MyModel)
In the same way you can extend the default model wrapper, you can extend the SSRM custom model wrapper by subclassing the rxe.ModelWrapperSSRM class. This allows you to customize the behavior of the model wrapper to fit your specific use case.
import reflex_enterprise as rxe
class MyCustomSSRMWrapper(rxe.ModelWrapperSSRM[MyModel]):
pass
The overridable methods are the same as the standard model wrapper.