[Feature Request] serverSide support
Liripo opened this issue · 6 comments
Currently, I can't seem to get the code below to work.
import dash_ag_grid as dag
import dash
from dash import Input, Output, html, dcc, no_update
import os
import pandas as pd
app = dash.Dash(__name__)
from sklearn.datasets import load_iris
iris = load_iris()
iris = pd.DataFrame(iris.data, columns=iris.feature_names)
app.layout = html.Div(
[
dag.AgGrid(
id="aggrid",
columnDefs=[{"field": i} for i in iris.columns],
enableEnterpriseModules = True,
licenseKey = os.environ['AGGRID_ENTERPRISE'],
rowModelType="serverSide",
columnSize="autoSize",
defaultColDef=dict(
resizable=True, sortable=True, filter=True, minWidth=100
),
dashGridOptions={"pagination": True},
),
]
)
@app.callback(
Output("aggrid", "getRowsResponse"),
Input("aggrid", "getRowsRequest"),
)
def infinite_scroll(request):
print(request)
if request is None:
return no_update
partial = iris.iloc[request["startRow"] : request["endRow"]]
return {"rowData": partial.to_dict("records"), "rowCount": len(iris.index)}
if __name__ == "__main__":
app.run_server(debug=True)
Hello @Liripo,
The serverSide rowModel doesnt come with this connection, it doesn't like the extra stuff in the request for some reason.
Here is a way that you can create your own.
https://community.plotly.com/t/serverside-rowmodeltype-in-dash-aggrid/76876/8?u=jinnyzor
Please note, the steps that I did here for getting the grids api are unnecessary and should be replaced with a simple:
grid = await dash_ag_grid.getApiAsync(id)
if (grid) {
...
}
Hello @BSd3v
It seems complicated. It would be great if some APIs could be provided in the python module.
Infinite and serverSide rowModels are more complex, and each use-case is different.
Infinite rowModel will work in most cases, unless you need info about rowGroupings, etc. Infinite will automatically give the getDetailRequest property available for the callback.
Regardless of which you choose, you will have to determine your filtering and sorting mechanism in python.
Infinite might fit your needs then.
Oh, okay, just realized.