On Saturday, February 25, 2017 at 1:10:10 AM UTC-5, Carlos Cesar Caballero 
wrote:
>
> Hi Anthony, thanks for your answer.
>
> We are using (besides web2py) the php yii2 framework. Yii2 has this 
> functionality specifying custom functions for sorting and filtering of 
> fields in grids (
> http://www.yiiframework.com/wiki/621/filter-sort-by-calculated-related-fields-in-gridview-yii-2-0/).
>  
> Will be very difficult to implement something like this in web2py?
>

It appears the linked Yii example is not fully generalizable -- it works 
for a virtual field that merely concatenates other fields because you can 
define searching and sorting queries for it that can be handled by the 
database. I don't think it would work with arbitrary Python expressions, 
many of which would not be able to be executed by the database in order to 
handle searching and sorting on the generated values.

In general, I'm not sure it makes sense for web2py virtual fields to be 
searchable and sortable because in order to work for all possible virtual 
field functions, the searching/sorting would have to be done in Python 
after selecting* all* records from the table (which may not be practical at 
all for large tables).

Instead, it would probably make sense to implement a more limited 
functionality that allows adding SQL expressions as additional columns, as 
discussed here: https://github.com/web2py/web2py/issues/1553.
 

> I am asking because the web2py source code sometimes overwhelmed me, the 
> grid is just a function with around 917 code lines and is a little 
> difficult to understand for me.
>

Agreed, the grid code has become somewhat unwieldy. It should probably be 
refactored into more modular code.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to