Forum OpenACS Q&A: listbuilder, groupby, orderby(s)

Collapse
Posted by Alexandre Simard on
Hi,

I'm trying to understand all the tools that listbuilder gives me, and I'm finding that groupby is very nearly useless. The doc says -groupby just creates a filter named groupby, which is what it does. Except a filter is used to eliminate rows (adding a where clause). -groupby should actually sort, in order for list items to be grouped in a logical manner by the template.

Therefore, my -groupby block is now down to its simplest expression:

    -groupby {
        label "Regroupement"
        values {
            {"Étiquette" record_label}
            {"Artiste" short_artist}
        }
    } \

Its serves two purposes:

- Print the groupby options in the <listfilters> tag output.
- Add the groupby property to the list so that <if @list_properties.groupby@ not nil> can be used in the template

I still have to add the correct sorting manually at the beginning of the TCL file:

if [info exists groupby] {
    set orderby $groupby
}

So once groupby is set, the orderby is invalidated.

So, what are my questions?

1. If someone can hit me in the face with something I'm doing blatantly wrong, I'd love it. groupby is underdocumented, so I'm flying blind. This blog post (https://openacs.org/blog/one-entry?entry_id=297278) is the only thing I could find, and it contains non-working code.

2. We'd love for sorting to work inside groups. For this, we'd need orderby to accept multiple columns, in order. Is this at all possible?

Thanks,

Alexandre

Collapse
Posted by Dave Bauer on
Here is what I did:

set group_by_values [list [list region { groupby region } [list orderby "region\ asc" ] ] ]
set groupby_orderby "region asc"
set order_by_list [list response_id [list  orderby_asc "${groupby_orderby}, res\ponse_id asc" orderby_desc "${groupby_orderby}, response_id asc"] \
        position    [list  orderby_asc "${groupby_orderby}, position asc" order\by_desc "${groupby_orderby}, position asc" ] \
        pretty_creation_date [list  orderby_asc "${groupby_orderby}, creation_d\ate asc" orderby_desc "${groupby_orderby}, creation_date asc"] \
                       region {orderby region}]

So to explain that, we only had one column to group on, so you can either group or not, in this case so its a little simpler. I dynamically build the orderby specification for each order by option to prepend the groupby column at the beginning of the orderby spec. This allows ordering by the group column, and also the orderby column.

I never did grasp all the ways to use group by, but maybe this example will help.

Collapse
Posted by Alexandre Simard on
Yes, I guess that's the only way to go, short of hacking template::list::orderby_clause to automatically prepend the groupby column, which I'll be doing soon enough.

Thanks, Dave! As far as I can tell, there's no other way to use groupby right now.

Collapse
Posted by Dave Bauer on
Alexandre, that sounds like a bug fix, not a hack! Please post a patch or let us know if you decide to fix it into the template::list code.
Collapse
Posted by Alexandre Simard on
OK, I will surely do. Do you know if there already is an open bug for this? I couldn't find one myself. Should I open a bug before submitting a patch, or just submit my patch when it's done? Thanks!