You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removed path from code exmaples and parameter explanations. Added explanation of old and new i.e. path vs request.query['mode']. Minor updates to parameter explanations. (#995)
- search_form: py4web FORM to be included as the search form. If
214
-
search_form is passed in then the developer is responsible for
215
-
applying the filter to the query passed in. This differs from
216
-
search_queries
217
-
- search_queries: list of query lists to use to build the search form.
218
-
Ignored if search_form is used
219
-
- columns: list of fields or columns to display on the list page,
220
-
see the :ref:`Custom columns` paragraph later.
221
-
If blank, the table will use all readable fields of the searched table
222
-
- show_id: show the record id field on list page - default = False
223
-
- orderby: pydal orderby field or list of fields
224
-
- left: if joining other tables, specify the pydal left expression here
225
-
- headings: list of headings to be used for list page - if not provided
226
-
use the field label
227
-
- create: URL to redirect to for creating records - set to True to
228
-
automatically generate the URL - set to False to not display the
229
-
button
230
-
- details: URL to redirect to for displaying records - set to True to
231
-
automatically generate the URL - set to False to not display the
232
-
button (*)
233
-
- editable: URL to redirect to for editing records - set to True to
234
-
automatically generate the URL - set to False to not display the
235
-
button (*)
236
-
- deletable: URL to redirect to for deleting records - set to True to
237
-
automatically generate the URL - set to False to not display the
238
-
button (*)
239
-
- validation: optional validation function to pass to create and edit forms
240
-
- pre_action_buttons: list of action_button instances to include before
241
-
the standard action buttons
242
-
- post_action_buttons: list of action_button instances to include after
243
-
the standard action buttons
244
-
- auto_process: Boolean - whether or not the grid should be processed
245
-
immediately. If False, developer must call grid.process() once all
246
-
params are setup
247
-
- rows_per_page: number of rows to display per page. Default 15
248
-
- include_action_button_text: boolean telling the grid whether or not
249
-
you want text on action buttons within your grid
250
-
- search_button_text: text to appear on the submit button on your
251
-
search form
252
-
- formstyle: py4web Form formstyle used to style your form when
253
-
automatically building CRUD forms
254
-
- grid_class_style: GridClassStyle class used to override defaults for
255
-
styling your rendered grid. Allows you to specify classes or styles
256
-
to apply at certain points in the grid
257
-
- icon_style: default: IconStyleFontawsome. used to get icon css classes.
258
-
Other options: IconStyle, IconStyleBootstrapIcons
259
-
- T: optional pluralize object
211
+
- query: pydal query to be processed
212
+
- search_form: py4web FORM to be included as the search form. If search_form is passed in then the developer is responsible for applying the filter to the query passed in. This differs from search_queries.
213
+
- search_queries: list of query lists to use to build the search form. Ignored if search_form is used.
214
+
- columns: list of fields or columns to display on the list page, see the :ref:`Custom columns` paragraph later. If blank, the table will use all readable fields of the searched table.
215
+
- show_id: show the record id field on list page. Default isNone, which enables automatic detection ifany field is of type"id".
216
+
- orderby: pydal orderby field orlist of fields. Controls the default sort order of the grid.
217
+
- left: if joining other tables, specify the pydal left expression here
218
+
- groupby: pydal groupby expression. Used to group results in the grid.
219
+
- headings: list of headings to be used forlist page -ifnot provided use the field label
220
+
- create: Controls whether the grid allows record creation. Can be True (show button), False (hide button), a URL string, or a callablefor custom logic.
221
+
- details: Controls whether the grid allows viewing record details. Can be True, False, a URL string, or a callablefor custom logic.
222
+
- editable: Controls whether the grid allows editing records. Can be True, False, a URL string, or a callablefor custom logic.
223
+
- deletable: Controls whether the grid allows deleting records. Can be True, False, a URL string, or a callablefor custom logic.
224
+
- required_fields: list of fields that must be included in the grid's queries and forms. Used to ensure certain fields are always loaded.
225
+
- validation: optional validation function to pass to create and edit forms
226
+
- pre_action_buttons: list of action_button instances to include before the standard action buttons
227
+
- post_action_buttons: list of action_button instances to include after the standard action buttons
228
+
- auto_process: Boolean - whether ornot the grid should be processed immediately. If False, developer must call grid.process() once all params are setup.
229
+
- rows_per_page: number of rows to display per page. Default 15
230
+
- include_action_button_text: boolean telling the grid whether ornot you want text on action buttons within your grid
231
+
- search_button_text: text to appear on the submit button on your search form
232
+
- formstyle: py4web Form formstyle used to style your form when automatically building CRUD forms
233
+
- grid_class_style: GridClassStyle class used to override defaults for styling your rendered grid. Allows you to specify classes or styles to apply at certain points in the grid
234
+
- icon_style: default: IconStyleFontawsome. used to get icon css classes. Other options: IconStyle, IconStyleBootstrapIcons
235
+
- T: optional pluralize object
260
236
261
237
(*) The parameters ``details``, ``editable``and``deletable`` can also take a **callable** that will
262
238
be passed the current row of the grid. This is useful because you can then turn a button on or off
@@ -280,15 +256,11 @@ There are two ways to build a search form:
280
256
- Provide a search_queries list
281
257
- Build your own custom search form
282
258
283
-
If you provide a search_queries list to grid, it will:
284
-
285
259
- build a search form. If more than one search query in the list, it
286
260
will also generate a dropdown to select which search field to search
287
261
against
288
-
- gather filter values and filter the grid
289
262
290
263
However, if this doesn’t give you enough flexibility you can provide
291
-
your own search form and handle all the filtering (building the queries)
292
264
by yourself.
293
265
294
266
CRUD settings
@@ -307,7 +279,6 @@ Custom columns
307
279
--------------
308
280
309
281
If the grid does not involve a join but displays results from a single table
310
-
you can specify a list of columns. Columns are highly customizable.
311
282
312
283
.. code:: python
313
284
@@ -348,7 +319,6 @@ Batman only, as explained before.
348
319
Using templates
349
320
---------------
350
321
351
-
Use the following to render your grid or CRUD forms in your templates.
352
322
353
323
Display the grid or a CRUD Form
354
324
@@ -385,16 +355,58 @@ the grid or a form. Use the following to decide:
385
355
[[pass]]
386
356
387
357
358
+
Grid 'path' parameter: Old vs New Usage
359
+
---------------------------------------
360
+
361
+
In previous versions of py4web, the `Grid`object required a `path` parameter in its constructor. This was used to help the grid parse the URLand determine the current action (such as select, edit, details, delete, etc.).
362
+
363
+
**Old usage example:**
364
+
365
+
.. code:: python
366
+
367
+
grid = Grid(
368
+
path=request.path,
369
+
query=(db.person.id >0),
370
+
# ...other parameters...
371
+
)
372
+
373
+
However, starting with py4web 1.20240501and later, the `path` parameter is no longer needed or supported. The grid now automatically determines the current action and routing from the py4web request context andURL parameters. You should simply omit the `path` argument and use the constructor as follows:
374
+
375
+
**New usage example:**
376
+
377
+
.. code:: python
378
+
379
+
grid = Grid(
380
+
query=(db.person.id >0),
381
+
# ...other parameters...
382
+
)
383
+
384
+
This change makes the API simpler and less error-prone. All routing and action handling is now managed by py4web's @action decorator and the request context, so you do not need to manually pass the path.
385
+
386
+
If you are updating older code, simply remove the `path` argument from your Grid instantiations.
387
+
388
+
Grid mode parameter (path replacement)
389
+
-------------------
390
+
391
+
The `Grid`object uses a `mode` variable, which is passed via the `request.query`objectin py4web. This variable determines what kind of page or form the grid will render. Possible values for`mode` are:
392
+
393
+
-`select`: Shows the main grid listing all records (default ifnot specified).
394
+
-`new`: Shows a form to create a new record.
395
+
-`details`: Shows a read-only form with details of a single record.
396
+
-`edit`: Shows a form to edit an existing record.
397
+
-`delete`: Shows a confirmation form to delete a record.
398
+
399
+
The grid automatically parses the `mode`from the URL query parameters. For example, if you visit `/myapp/mygrid?mode=edit&id=5`, the grid will render the edit form for the record withID5. If no `mode`is specified, the grid defaults to `select`and shows the main table view.
400
+
401
+
If you want to customize navigation or actions, you can generate links or buttons that set the desired `mode`and`id`in the query string.
402
+
388
403
Customizing style
389
-
-----------------
404
+
-------------------
390
405
391
406
You can provide your own formstyle or grid classes and style to grid.
392
407
393
-
- formstyle is the same as a Form formstyle, used to style the CRUD
394
408
forms.
395
-
- grid_class_style is a class that provides the classes and/or styles
396
409
used for certain portions of the grid.
397
-
- icon_style is a class which provides the icon classes, for example for FontAwesome
398
410
399
411
The default ``GridClassStyle``- based on **no.css**, primarily uses styles to
400
412
modify the layout of the grid. We've already seen that it's possible
@@ -405,24 +417,19 @@ your choice.
405
417
406
418
With icon_style, you can customize the icon font used. Currently, the following exist:
407
419
408
-
- ``IconStyleFontawsome`` is the current default (for backwards compatibility). You need
409
420
to add `fontawesome <https://fontawesome.com/>`__ icon font CSS to use this.
410
-
- ``IconStyle`` which doesn't correspond to any font or icon set. It inserts simple
411
421
css classes like ``icon-edit-button`` which you can write your own css for.
412
-
- ``IconStyleBootstrapIcons`` You need to add the icon font CSS from
0 commit comments