Grids and lists¶
The collection side: a table for the desktop, a list with drill-down for the phone, and the chrome wrapper that adds create, edit and delete to either. See Components for the guide.
ModelGrid
¶
Renders a Pydantic model collection as an ag-Grid table.
Create via factory methods: ModelGrid.from_list(Type, items) — in-memory list ModelGrid.from_json(Type, path) — JSON file ModelGrid.from_adapter(Type, adapter) — any CollectionAdapter
After render(), the NiceGUI ag-Grid element is available as grid.widget. Apply classes/style/props via grid.widget after render: grid.render() grid.widget.classes('w-full') Call update_rows() to refresh the displayed data from the adapter.
Source code in niceview/modelgrid.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
from_list
classmethod
¶
from_list(
item_type: type[T],
items: list[T],
**kwargs: Unpack[_ModelGridOptionInputs],
) -> Self
Create a grid from an in-memory list.
Pass a plain list for manual control: the grid updates only when update_rows() is called explicitly (e.g. via the EditGridWrapper Refresh button).
Pass an ObservableList for automatic updates: the grid re-renders whenever the list is mutated structurally (append, delete, replace) without any explicit update_rows() call.
Return type is Self so subclasses (e.g. ModelGridInlineEdit) are returned as their own type.
Source code in niceview/modelgrid.py
from_adapter
classmethod
¶
from_adapter(
item_type: type[T],
adapter: CollectionAdapter,
**kwargs: Unpack[_ModelGridOptionInputs],
) -> Self
Create an instance from any CollectionAdapter. Equivalent to the constructor — provided for API symmetry with ModelForm.from_adapter(). Return type is Self so subclasses (e.g. ModelGridInlineEdit) are returned as their own type.
Source code in niceview/modelgrid.py
from_json
classmethod
¶
from_json(
item_type: type[T],
path_name: Path,
*,
create_if_not_exist: bool = True,
**kwargs: Unpack[_ModelGridOptionInputs],
) -> Self
Create an instance backed by a JSON file via JsonListAdapter. The file is created with an empty list if it does not exist. Call grid.adapter.reload() + grid.update_rows() to refresh from disk. Return type is Self so subclasses (e.g. ModelGridInlineEdit) are returned as their own type.
Source code in niceview/modelgrid.py
with_repositories
¶
Register repositories for modelselect fields, so the grid shows their labels (and, when inline-editable, offers a select of the related items). Keys are a field name (preferred) or the related model type. May be called after render() — the columns and rows are refreshed in place.
Source code in niceview/modelgrid.py
on_select
¶
on_select(
callback: Handler[TableItemSelectEventArguments],
) -> Self
Add a callback invoked when the row selection changes. The event carries row_key and item (both None when the selection was cleared), mirroring ModelList.on_select. Only meaningful when rowSelection='single'.
Source code in niceview/modelgrid.py
update_rows
¶
update_rows() -> Self
Refresh the displayed rows from the adapter.
Source code in niceview/modelgrid.py
render
¶
render() -> Self
Render the ag-Grid widget into the current NiceGUI context.
Source code in niceview/modelgrid.py
ModelGridInlineEdit
¶
Bases: ModelGrid
Extends ModelGrid with inline cell editing. Each cell edit is validated against the Pydantic model and persisted via the adapter. Register on_change() callbacks to react to successful or failed cell edits.
Source code in niceview/modelgrid.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
on_change
¶
on_change(
callback: Handler[TableItemFieldEventArguments],
) -> Self
Add a callback invoked on each inline cell edit (success or validation failure).
Source code in niceview/modelgrid.py
TableItemEventArguments
dataclass
¶
Bases: ClickEventArguments
Fired by EditGridWrapper.on_change after a successful create, update, or delete.
Source code in niceview/modelgrid.py
EditGridWrapper
¶
Chrome wrapper for ModelGrid: renders title, description, and CRUD buttons (add, edit, delete, refresh) above the grid.
Title semantics: omitted or None → auto-generated title '{ItemType} List'; '' → no title; any other string → that title. Button semantics ('' and None differ from the title!): '' → icon-only button (the default), a string → labeled button, None → button hidden.
on_add replaces the default Add action (create item_type() and open the create dialog)
with a handler of your own; the other CRUD buttons keep their built-in behaviour.
chrome_actions adds the application's own buttons to that row — the same FormAction a
form places between its fields, here left of niceview's own so those keep the right edge
they have everywhere. Their on_click receives a GridActionEventArguments, with the
selected row rather than a form's item.
search=True adds a free-text search box to the title row, filtering rows across all
columns as the user types — ag-grid's client-side quick filter, not a server round-trip.
After render(), the NiceGUI elements are exposed for further styling: wrapper.title → ui.label | None wrapper.description → ui.markdown | None wrapper.title_row → ui.row | None wrapper.search_input → ui.input | None wrapper.add_button → ui.button | None wrapper.edit_button → ui.button | None wrapper.delete_button → ui.button | None wrapper.refresh_button → ui.button | None wrapper.action_buttons → dict[str, ui.button] — from chrome_actions=
Source code in niceview/editwrapper.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
from_list
classmethod
¶
from_list(
item_type: type[T],
items: list[T],
*,
inline_edit: bool = False,
**kwargs: Unpack[_EditGridWrapperFactoryInputs],
) -> Self
Create an EditGridWrapper backed by an in-memory list. Call render() (fluent: from_list(...).render()) to draw it.
Source code in niceview/editwrapper.py
from_json
classmethod
¶
from_json(
item_type: type[T],
path_name: Path,
*,
create_if_not_exist: bool = True,
inline_edit: bool = False,
**kwargs: Unpack[_EditGridWrapperFactoryInputs],
) -> Self
Create an EditGridWrapper backed by a JSON file. Call render() to draw it.
Source code in niceview/editwrapper.py
from_adapter
classmethod
¶
from_adapter(
item_type: type[T],
adapter: CollectionAdapter,
*,
inline_edit: bool = False,
**kwargs: Unpack[_EditGridWrapperFactoryInputs],
) -> Self
Create an EditGridWrapper backed by any CollectionAdapter. Call render() to draw it.
Source code in niceview/editwrapper.py
with_repositories
¶
Set repositories for modelselect fields — the create/edit dialogs and the grid itself, so modelselect columns show their labels (and offer a select where applicable). Keys are a field name (preferred) or the related model type. Additive, and merged into the grid's own registrations rather than replacing them.
Source code in niceview/editwrapper.py
on_change
¶
on_change(
callback: Handler[TableItemEventArguments],
) -> Self
Add a callback invoked after each successful create, update, or delete.
Source code in niceview/editwrapper.py
render
¶
render() -> Self
Render title, description, CRUD buttons, and the grid into the current NiceGUI context.
Source code in niceview/editwrapper.py
refresh
¶
create_item
async
¶
Open the create dialog and, on confirmation, persist the new item.
Source code in niceview/editwrapper.py
update_item
async
¶
Open the edit dialog for the selected row and, on confirmation, persist changes.
Source code in niceview/editwrapper.py
delete_item
async
¶
Ask for confirmation and delete the selected row.
Source code in niceview/editwrapper.py
default_edit_create_handler
async
¶
Show a modal dialog to create or edit an item. Returns True if the user confirmed.
The dialog renders a ModelForm for the item and presents Cancel / Create-or-Ok buttons. On confirm, pending widget values are flushed into the validated item before the dialog closes — this guards against the edge case where a blur event arrives after the click over WebSocket (browsers fire blur before click, but message ordering is not guaranteed).
Source code in niceview/editwrapper.py
GridActionEventArguments
dataclass
¶
Bases: UiEventArguments
What an action's on_click receives in an EditGridWrapper's title row.
A grid has no item of its own, it has a selection: row_key and item are the selected
row, or None when nothing is selected — which an action that works on one has to check,
the same way Edit and Delete do.
Source code in niceview/editwrapper.py
ModelList
¶
Renders a Pydantic model collection as a Quasar list (ui.list / ui.item). Each item shows a title line and an optional subtitle, with a chevron indicating drill-down.
The first visible field is used as the title; the next two as subtitle by default. Override with title_field= and subtitle_fields=.
Create via factory methods: ModelList.from_list(Type, items) — in-memory list ModelList.from_json(Type, path) — JSON file ModelList.from_adapter(Type, adapter) — any CollectionAdapter
After render(), the NiceGUI list element is available as .widget. Call update_rows() to refresh from the adapter.
The look of the list and its rows comes from the chrome style — application-wide via niceview.style.set_chrome_style(), or for this list alone via chrome_style=. Styling .widget directly is not enough: update_rows() rebuilds every row inside it.
Source code in niceview/modellist.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
from_list
classmethod
¶
from_list(
item_type: type[T],
items: list[T],
**kwargs: Unpack[_ModelListOptionInputs],
) -> Self
Create a ModelList backed by an in-memory list.
Source code in niceview/modellist.py
from_adapter
classmethod
¶
from_adapter(
item_type: type[T],
adapter: CollectionAdapter,
**kwargs: Unpack[_ModelListOptionInputs],
) -> Self
Create a ModelList from any CollectionAdapter.
Source code in niceview/modellist.py
from_json
classmethod
¶
from_json(
item_type: type[T],
path_name: Path,
*,
create_if_not_exist: bool = True,
**kwargs: Unpack[_ModelListOptionInputs],
) -> Self
Create a ModelList backed by a JSON file.
Source code in niceview/modellist.py
on_select
¶
on_select(
callback: Handler[ListItemSelectEventArguments],
) -> Self
Add a callback invoked when the user taps an item.
Source code in niceview/modellist.py
with_repositories
¶
Register repositories for modelselect fields shown as title/subtitle, so a stored key displays the referenced item's label. Keys are a field name (preferred) or the related model type — the same form the other components accept.
Source code in niceview/modellist.py
render
¶
render() -> Self
Render the list widget into the current NiceGUI context.
Source code in niceview/modellist.py
DrillDownWrapper
¶
Embeddable list <-> detail navigation. render() draws a title row (Add in list view; Back + item title + Delete in detail view) plus a body that swaps between a list view and a per-item detail view, with a slide animation on every swap. No NiceGUI page/route of its own — call it inside your own ui.page / ui.card / ui.column, same as any other niceview widget.
Default rendering (both overridable): - list view: ModelList-style rows (title/subtitle from field values) - detail view: an autosaving ModelForm.from_adapter(item_type, adapter, key)
list_actions and detail_actions add the application's own buttons to the title row — the
same FormAction a form places between its fields — right-aligned just left of niceview's
own button of that view (Add, Delete), so niceview's own button keeps the right edge it has
everywhere. list_actions sit in the list view and are hidden in the detail view, and vice
versa: each view shows only its own actions, since an action about no single item and one
about the item on screen are different things. list_actions get a
DrillDownListActionEventArguments (no key/item — there is no single item in the list
view); detail_actions get a DrillDownActionEventArguments naming the item on screen.
chrome_actions is accepted as an alias of detail_actions.
Override render_list_item / render_detail for custom layout, heterogeneous item types (resolve the concrete pydantic type per item inside render_detail), or non-form content — e.g. rendering a nested DrillDownWrapper for a DirectoryAdapter's files. See README.
After render(), the title row elements are exposed for further styling -- built once and updated (text/visibility only) rather than recreated on every list<->detail navigation, so styling applied here is not lost: wrapper.title_row → ui.row | None wrapper.title → ui.label | None (list title, or the current item's title in detail view) wrapper.description → ui.markdown | None (None entirely if description= is unset) wrapper.back_button → ui.button | None (visible in detail always; in list only if on_back= is set) wrapper.search_input → ui.input | None (visible in list view; None entirely unless search=True) wrapper.add_button → ui.button | None (visible in list view; None entirely if add_button=None) wrapper.delete_button → ui.button | None (visible in detail view; None entirely if delete_button=None) wrapper.list_action_buttons → dict[str, ui.button] (visible in list view; from list_actions=) wrapper.action_buttons → dict[str, ui.button] (visible in detail view; from detail_actions= / chrome_actions=) For the shared look of the title row rather than a single instance of it, see niceview.style.set_chrome_style() and the chrome_style= option. The body (list/detail content) is not exposed: unlike the title row, it is genuinely torn down and rebuilt on every navigation (list and detail are structurally different content, and the swap is where the slide animation lives), so any styling applied to it would be silently lost on the next navigation.
Usage: wrapper = DrillDownWrapper.from_list(User, items, title='Users') wrapper.render()
Source code in niceview/drilldown.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
from_list
classmethod
¶
from_list(
item_type: type[T],
items: list[T],
**kwargs: Unpack[_DrillDownWrapperOptionInputs],
) -> Self
Create a DrillDownWrapper backed by an in-memory list.
Source code in niceview/drilldown.py
from_adapter
classmethod
¶
from_adapter(
item_type: type[T],
adapter: CollectionAdapter,
**kwargs: Unpack[_DrillDownWrapperOptionInputs],
) -> Self
Create a DrillDownWrapper from any CollectionAdapter.
Source code in niceview/drilldown.py
from_json
classmethod
¶
from_json(
item_type: type[T],
path_name: Path,
*,
create_if_not_exist: bool = True,
**kwargs: Unpack[_DrillDownWrapperOptionInputs],
) -> Self
Create a DrillDownWrapper backed by a JSON file.
Source code in niceview/drilldown.py
with_repositories
¶
Register repositories for modelselect fields, forwarded to both views: the list rows (a key field shows the referenced label) and the default detail form (its selects). Keys are a field name (preferred) or the related model type. Call before render(). Additive: a later call adds to (and overrides) earlier registrations.
Source code in niceview/drilldown.py
open
¶
Navigate to the detail view for key — e.g. from a custom on_add handler.
Source code in niceview/drilldown.py
render
¶
render() -> Self
Render the title row and list/detail body into the current NiceGUI context.
Source code in niceview/drilldown.py
DrillDownActionEventArguments
dataclass
¶
Bases: UiEventArguments
What a detail_actions action's on_click receives in a DrillDownWrapper's title row.
Those buttons belong to the detail view — key and item are the item on screen, never
None, because there is nothing to click them on in the list view. See
DrillDownListActionEventArguments for list_actions, which has neither.