How to sort custom filter dropdown list options?

Greetings!
In the following piece of a browse screen descriptor there’s declaration of the filter with one custom field.

<filter id="genericFilter"
                    applyTo="cardsTable"
                    datasource="cardsDs">
                <properties include=".*"/>
                <custom id="customFilter" name="composedEntities"
                        paramClass="com.haulmont.company.entity.ComposedEntity"
                        join="join e.composedEntities ce" inExpr="true"
                        paramWhere="{E}.usedForFiltering = true">
                    ce.id in (?)
                </custom>
</filter>

Options for this custom field in the dropdown list are filtered correctly by the paramWhere attribute, but I failed to find a proper way to sort this list.

Is there an easy way to sort options for my custom filter dropdown list, say, by the ce.name property?

Hi,

You can add add an order by statement right in the paramWhere clause, for example:

<custom id="customFilter" name="composedEntities"
        paramClass="com.haulmont.company.entity.ComposedEntity"
        join="join e.composedEntities ce" inExpr="true"
        paramWhere="{E}.usedForFiltering = true order by {E}.name desc">
    ce.id in (?)
</custom>

Hi, Olga!

Thank you for the respond.

I’ve tried this approach, but the option list query was rendered as:

select e from company$ComposedEntity e where (e.usedForFiltering = true and (e.deleteTs is null) order by e.name)

But that is not a valid query, the browse screen throws an error.

I’ve tried an example similar to yours but using the sample-sales data model, and no error is thrown:

<filter id="filter"
        applyTo="ordersTable"
        datasource="ordersDs">
    <properties include=".*"/>
    <custom name="custom"
            paramClass="com.company.sales.entity.Customer"
            join="join e.customer c" inExpr="true"
            paramWhere="{E}.email is not null order by {E}.name desc">
        c.id in (?)
    </custom>
</filter>

You can attach here a small sample project with your entities and screens, and we’ll try to help you.

Worked for me on this test project as well.
I guess it’s because CUBA of the latest version doesn’t put any (e.deleteTs is null) part in the middle of the where clause.

You can easily confirm that by putting something like “{E}.email is not null a order by {E}.name desc” in your paramWhere attribute.

I bet that the resulting JPQL-query in the error message you’d get in the browse screen will look like that:

select e from sales$Customer e where e.email is not null a order by {E}.name desc

  • without any “e.deleteTs is null” part.

But that doesn’t really work for my project, since I can’t just swich to a newer CUBA.

Thank you for your time anyway!

What platform version do you use? We’ll see what we can do.

1 Like

I use 5.9.2 version of CUBA.