Fixes issue
17072: Default sort defined in ad_field is not taking into account
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl Tue May 10 05:39:33 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl Tue May 10 05:59:34 2011 +0200
@@ -103,6 +103,7 @@
],
whereClause: '${data.whereClause?js_string}',
orderByClause: '${data.orderByClause?js_string}',
+ sortField: '${data.sortField?js_string}',
filterClause: '${data.filterClause?js_string}',
foreignKeyFieldNames:[
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java Tue May 10 05:39:33 2011 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java Tue May 10 05:59:34 2011 +0200
@@ -89,6 +89,27 @@
if (tab.getHqlorderbyclause() != null) {
return tab.getHqlorderbyclause();
}
+
+ return "";
+ }
+
+ public String getSortField() {
+ if (getOrderByClause().length() > 0) {
+ return "";
+ }
+
+ long lowestSortno = Long.MAX_VALUE;
+ LocalField sortByField = null;
+ for (LocalField localField : getFields()) {
+ final Long recordSortno = localField.getField().getRecordSortNo();
+ if (localField.isInitialShow() && recordSortno != null && recordSortno < lowestSortno) {
+ sortByField = localField;
+ }
+ }
+ if (sortByField != null && sortByField.getProperty() != null) {
+ return sortByField.getProperty().getName();
+ }
+
// use 2 examples of sequence number of line no
if (entity.hasProperty(Tab.PROPERTY_SEQUENCENUMBER)) {
return Tab.PROPERTY_SEQUENCENUMBER;
@@ -97,7 +118,12 @@
return OrderLine.PROPERTY_LINENO;
}
- return JsonConstants.IDENTIFIER;
+ for (LocalField localField : getFields()) {
+ if (localField.getProperty() != null && localField.getProperty().isIdentifier()) {
+ return localField.getProperty().getName();
+ }
+ }
+ return "";
}
public String getFilterClause() {