SQLFORM.grid: using groupby disables create?

61 views
Skip to first unread message

Scott Hunter

unread,
Dec 3, 2016, 8:53:45 AM12/3/16
to web2py-users
I have a SQLFORM.grid in which I would like to use groupby as well as be able to create records.  But when I supply the groupby parameter, the Add Record button disappears, and can be made to re-appear if the only thing I change is remove the groupby parameter.

Is this a bug?  If it is a feature, can someone explain the reasoning behind it, and how I would best work around it?

- Scott

Anthony

unread,
Dec 3, 2016, 11:11:58 AM12/3/16
to web2py-users
This is tricky. Write operations (as well as the details view) are disabled with groupby because the rows in the grid do not necessarily represent individual records. Of course, that shouldn't necessarily preclude adding new records, but from a user perspective, we have to think of what is meant by "Add" in the context of a table that is displaying aggregated data rather than individual records. Are you adding a new row to the grid (which doesn't quite make sense) or a new individual record to the table used to generate the grid (sensible, but maybe not as clear)?

I don't have a strong opinion, but I suppose it wouldn't be a bad idea to at least allow the developer the option of enabling create with groupby. In that case, though, we might have to default to create=False for backward compatibility.

Feel free to file a Github issue and refer to this thread.

Anthony

Scott Hunter

unread,
Dec 3, 2016, 1:32:57 PM12/3/16
to web2py-users
In my case, I have records with 2 fields, A & B; I want one record to be displayed for each distinct value of A when B is either 1 or 2, but it is possible that each will be present, so I use groupby A to avoid duplication.

I tried using a smartgrid, but it exhibited the same groupby/add behavior (although maybe I could use its constraint parameter to accomplish this without using groupby).

- Scott
Reply all
Reply to author
Forward
0 new messages