Thanks Anthony. Already updated the Github issue and created a post in the developers.
domingo, 7 de Abril de 2019 às 20:28:26 UTC+1, Anthony escreveu: > > Yes, as noted, that code inverts the sort order for date/time fields when > the field is clicked, but there is no inversion when using the orderby > argument. I'm not sure why the order is inverted for such fields. Maybe > bring it up in the developers group. > > On Sunday, April 7, 2019 at 3:19:51 PM UTC-4, João Matos wrote: >> >> I think I found the source of the problem. >> After following the function in the previous message, I arrived at this >> code inside the linsert function (line 2779) . >> >> exception = sort_field.type in ('date', 'datetime', >> 'time') >> if exception: >> desc_icon, asc_icon = sorter_icons >> orderby = (order[:1] == '~' and sort_field) or ~ >> sort_field >> else: >> orderby = (order[:1] == '~' and ~sort_field) or >> sort_field >> >> If I change it to >> >> exception = sort_field.type in ('date', 'datetime', >> 'time') >> # if exception: >> # desc_icon, asc_icon = sorter_icons >> # orderby = (order[:1] == '~' and sort_field) or >> ~sort_field >> #else: >> orderby = (order[:1] == '~' and ~sort_field) or >> sort_field >> >> Now the date sorting works fine. >> >> There is also another code segment in line 2641 with the same purpose >> that may need the same change, but that segment isn't run with my >> application, only the segment at line 2779. >> >> >> domingo, 7 de Abril de 2019 às 19:43:50 UTC+1, João Matos escreveu: >>> >>> I think I found the problem (I don't have the solution). >>> >>> In gluon\sqlhtml.py there is this function >>> >>> def fix_orderby(orderby): >>> if not auto_pagination: >>> return orderby >>> # enforce always an ORDER clause to avoid >>> # pagination errors. field_id is needed anyhow, >>> # is unique and usually indexed. See issue #679 >>> if not orderby: >>> orderby = field_id >>> elif isinstance(orderby, list): >>> orderby = reduce(lambda a,b: a|b, orderby) >>> elif isinstance(orderby, Field) and orderby is not field_id: >>> print('inside2') >>> # here we're with an ASC order on a field stored as >>> orderby >>> orderby = orderby | field_id >>> elif (isinstance(orderby, Expression) and >>> orderby.first and orderby.first is not field_id): >>> print('inside3') >>> # here we're with a DESC order on a field stored as >>> orderby.first >>> orderby = orderby | field_id >>> return orderby >>> >>> where I added the 2 prints. >>> A field that works correct shows inside2 on the first run and inside3 on >>> the second. >>> The date field always shows inside2. >>> >>> Any ideas? >>> >>> Do you use Telegram? There is an online web2py international group. It >>> would be great if you and others web2py core devs joined. >>> >>> >>> >>> >>> domingo, 7 de Abril de 2019 às 19:22:34 UTC+1, Anthony escreveu: >>>> >>>> On Saturday, April 6, 2019 at 3:41:50 PM UTC-4, João Matos wrote: >>>>> >>>>> Thanks Anthony. I will open an issue (I still haven't enough know how >>>>> to make a PR). I hope some time in the future. >>>>> >>>>> I don't want to abuse your help, but I have another issue that is >>>>> viewable with the minimal app I sent you. >>>>> If you create 2 records with different dates, and try to change the >>>>> grid's sort order you will notice that the URL changes, the page reloads >>>>> but the grid doesn't change. >>>>> I checked the db stats SQL statements and they stay the same (they >>>>> don't change the ORDER). >>>>> I think there is a bug with the sorting of date columns when they are >>>>> the predefined orderby. Can you try it and give me your input. >>>>> >>>> >>>> Definitely a bug -- feel free to report on Github. May have to do with >>>> the fact that when clicking to sort, the grid code inverts the order for >>>> date/time fields, but does not appear to do so when a date/time field is >>>> specified in the orderby argument. >>>> >>>> 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.