Is it possible to disable grid sorting for some columns only?

20 views
Skip to first unread message

João Matos

unread,
Mar 29, 2019, 7:31:08 AM3/29/19
to web2py-users
Is it possible to disable grid sorting for some columns only?

João Matos

unread,
Mar 29, 2019, 5:58:51 PM3/29/19
to web2py-users
Found a kludge.

    # Remove sorting from specific columns.
    grid
.elements('a', replace=remove_sorting)

which uses this function

def remove_sorting(html: gluon.HTML) -> Union[str, gluon.HTML]:
   
"""Remove HTML tag if it contains specific words.

    :param html: HTML.
    :return: Original HTML or text inside HTML tags w/specific words.
    """

    text
= str(html)
   
if ('power_supply' in text or 'automation' in text or 'doors' in text
           
or 'sg_model_power' in text):
       
return text.split('>')[1].split('<')[0]
   
return html


Is there a better way?

Reply all
Reply to author
Forward
0 new messages