Is it possible to sort the grid search fields list?

36 views
Skip to first unread message

João Matos

unread,
Mar 12, 2019, 9:58:20 PM3/12/19
to web...@googlegroups.com
Hello,

Is it possible to sort the grid search fields list?

Thanks,

JM

黄祥

unread,
Mar 12, 2019, 10:27:14 PM3/12/19
to web2py-users
is the sqlform.grid(sortable=True) doesnt meet your requirement ?
ref:

best regards,
stifan

João Matos

unread,
Mar 13, 2019, 4:44:45 AM3/13/19
to web2py-users
That sorts the grid not the grid's search fields list.

Leonel Câmara

unread,
Mar 13, 2019, 6:16:11 AM3/13/19
to web2py-users
No, not right now it isn't. What's possible is to make your own search_widget which could do the sorting of the search fields.

João Matos

unread,
Mar 13, 2019, 7:22:53 AM3/13/19
to web2py-users
:(

Not even make it show the fields in the same order they are in the grid's fields argument?

João Matos

unread,
Apr 3, 2019, 5:12:20 PM4/3/19
to web2py-users
Found a solution.

In the controller, after grid creation:
        # Sort grid's search fields list.
        grid
.element('#w2p_query_fields').components = sort_grid_search_fields_list(grid)


In a modules file
def sort_grid_search_fields_list(grid):
   
# type: (grid: gluon.DIV) -> List[gluon.OPTION]
   
"""Sort grid's search fields list.

    :param grid: Grid.
    :return: Sorted search fields list (HTML options).
    """

    keys
= []  # type: List[str]
    elements
= {}  # type: Dict[str, str]
   
for element in grid.element('#w2p_query_fields').components:  # type: gluon.OPTION
        keys
.append(element.flatten())
        elements
[element.flatten()] = element['_value']
    keys
.sort(key=str.lower)
   
return [gluon.OPTION(key, _value=elements[key]) for key in keys]


quarta-feira, 13 de Março de 2019 às 10:16:11 UTC, Leonel Câmara escreveu:
Reply all
Reply to author
Forward
0 new messages