AG-Grid integration¶
django-grid-view provides HTMX-safe helpers, toolbar partials, and a save API for column presets and searches. You own the AG-Grid instance — the package does not create gridApi for you.
Load CDN scripts outside HTMX swaps¶
Put AG Grid and Sortable in your base template, not inside fragments replaced by HTMX:
<script src="https://cdn.jsdelivr.net/npm/ag-grid-community@31.3.2/dist/ag-grid-community.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
Also load the django-grid-view bundle (once per page):
Minimal grid page¶
<div id="products-grid" class="ag-theme-quartz-dark"></div>
<script>
window.ProductsGrid = {
columnDefs: ProductColumns,
rowModelType: "infinite",
cacheBlockSize: 200,
context: { gridId: "products" },
};
</script>
{% django_grid_view_scripts grid_id="products" options_var="ProductsGrid" container_id="products-grid" %}
django_grid_view_scripts initializes the grid, wires search/modal UI, and persists settings when the user is logged in.
Partials¶
Compose toolbar, search, and modal separately:
{% render_django_grid_view_toolbar grid_id="products" %}
{% render_django_grid_view_search grid_id="products" %}
{% render_django_grid_view_modal grid_id="products" %}
Or use the combined toolbar + modal tag. Optional plugins:
{% include "django_grid_view/plugins/smart_filter.html" %}
{% include "django_grid_view/plugins/advanced_search.html" %}
{% include "django_grid_view/plugins/custom_tooltip.html" %}
Runtime rules¶
- Never load AG Grid CDN scripts inside HTMX-swapped content — scripts would re-run and break grid state.
- For infinite row model, do not use
quickFilterTextorautoHeight. Use the package search integration (manager._searchText) and filter on the server. - Define
columnDefs(or youroptions_varobject) beforedjango_grid_view_scriptsruns.
KPI and charts on filtered grid rows¶
Python renders unresolved KPI specs; the browser aggregates visible rows:
var adapter = GridView.createAgGridAdapter(gridApi);
GridView.bindGridKpis({ gridAdapter: adapter });
Charts with data_source: "grid_filtered" update on filter/sort via GridView.bindGridFilteredCharts. See JavaScript API and Charts and KPIs.
Saved preferences¶
Per-user column presets and searches use GridPreference and POST /api/django-grid-view/save/. See Saved preferences.