dsRequest.setSortBy seems not to work

Hi,

using 2.5.2011-09-19

I need to change the sortby fields coming from client on the serverside,
but dsRequest.setSortBy(new ArrayList<String>(){“field1”, “field2”});
seems not to be working.

Description:

dsRequest.getSortByFields() -> “fieldA”, “fieldB”
dsRequest.setSortBy(new ArrayList<String>(){“field1”, “field2”});

For the generated sql query the order by clause will be empty.

Can you tell me, why this isn’t working?
And what about this method, it’s not in API:
There is also dsRequest.setSelectSortByFields(true)

Thanks,

David

You need to pass an instance of List rather than a Java Array. If you already are, then look for a more basic coding error such as calling setSortBy() on the wrong DSRequest.

The DataSourceField has the property customSQL=“true” .

Seems like this is the reason I will not be generated in the SQL Order by clause.
I haven’t found anything in the API. Is there an easy way to enable sorting on this custom field.

In my case, if I pass the name of the field to setsortby, i would expect the native name to be used.

You can override the customSQL setting on a given field by specifying that field in a customValueFields clause on the specific operationBinding, but be aware that this is going to cause the SQL generator to also try to select that field. Alternatively, you can specify an <orderClause> on the specific operationBinding. All of this is documented.

Another question: are you sure that marking that field customSQL is what you really want?

Hi,
thanks for reply.

My situation is the following:
I conditional need to join another table (use another field with tableName=“different” instead of another one), where orderby should work, too.

The default orderClause should not be changed, but be generated.

When using customSQL=“true” and customValueFields and dsRequest.setSortField(fieldName), the field will not appear in the $defaultOrderClause

As a solution I put velocity inside of customSelectClause of the datasourcefield, to use one or the other table.

Just to be clear: are you saying that you specified customSQL=true on a field, and then included that field’s name in an operationBinding-level customValueFields property, and the generated defaultOrderClause did not include that field? Did it generate code for that field in the defaultSelectClause?