IDEMPIERE-3883:preserve sorting of info window (fix issue when column display changed)
This commit is contained in:
parent
bd00fdc42c
commit
f1fb314422
|
@ -1633,10 +1633,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
|
|||
dataSql = dataSql + " " + otherClause;
|
||||
}
|
||||
|
||||
if (indexOrderColumn > -1)
|
||||
dataSql = dataSql + getUserOrderClause();
|
||||
else
|
||||
dataSql = dataSql + m_sqlOrder;
|
||||
dataSql = dataSql + getUserOrderClause();
|
||||
|
||||
if (end > start && isUseDatabasePaging() && DB.getDatabase().isPagingSupported())
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ import org.adempiere.webui.event.ValueChangeListener;
|
|||
import org.adempiere.webui.event.WTableModelEvent;
|
||||
import org.adempiere.webui.event.WTableModelListener;
|
||||
import org.adempiere.webui.factory.InfoManager;
|
||||
import org.adempiere.webui.info.InfoWindow;
|
||||
import org.adempiere.webui.part.ITabOnSelectHandler;
|
||||
import org.adempiere.webui.part.WindowContainer;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
|
@ -374,6 +375,7 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
|||
private String m_sqlUserOrder;
|
||||
/* sql column of infocolumn (can be alias) */
|
||||
protected int indexOrderColumn = -1;
|
||||
protected String sqlOrderColumn;
|
||||
protected Boolean isColumnSortAscending = null;
|
||||
/**ValueChange listeners */
|
||||
private ArrayList<ValueChangeListener> listeners = new ArrayList<ValueChangeListener>();
|
||||
|
@ -1041,10 +1043,9 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
|||
int index = sql.lastIndexOf(" WHERE");
|
||||
sql.delete(index, sql.length());
|
||||
}
|
||||
if (indexOrderColumn > -1)
|
||||
sql.append(getUserOrderClause());
|
||||
else
|
||||
sql.append(m_sqlOrder);
|
||||
|
||||
sql.append(getUserOrderClause());
|
||||
|
||||
dataSql = Msg.parseTranslation(Env.getCtx(), sql.toString()); // Variables
|
||||
dataSql = MRole.getDefault().addAccessSQL(dataSql, getTableName(),
|
||||
MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
|
||||
|
@ -1055,14 +1056,40 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
|||
return dataSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* column of grid isn't fix, it can change by display logic of column each time load data
|
||||
* {@link InfoWindow#prepareTable(ColumnInfo[], String, String, String)}
|
||||
* so need to validate it by compare sql of current sort column
|
||||
*/
|
||||
protected void validateOrderIndex() {
|
||||
if (indexOrderColumn > 0 && (indexOrderColumn + 1 > p_layout.length || !p_layout[indexOrderColumn].getColSQL().trim().equals(sqlOrderColumn))) {
|
||||
// try to find out new index of ordered column, in case has other column is hide or display
|
||||
for (int testIndex = 0; testIndex < p_layout.length; testIndex++) {
|
||||
if (p_layout[testIndex].getColSQL().trim().equals(sqlOrderColumn)) {
|
||||
indexOrderColumn = testIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// index still incorrect and can't find out new index (ordered column become hide column)
|
||||
if (indexOrderColumn > 0 && (indexOrderColumn + 1 > p_layout.length || !p_layout[indexOrderColumn].getColSQL().trim().equals(sqlOrderColumn))) {
|
||||
indexOrderColumn = -1;
|
||||
sqlOrderColumn = null;
|
||||
m_sqlUserOrder = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* build order clause of current sort order, and save it to m_sqlUserOrder
|
||||
* @return
|
||||
*/
|
||||
protected String getUserOrderClause() {
|
||||
validateOrderIndex();
|
||||
if (indexOrderColumn < 0) {
|
||||
return null;
|
||||
return m_sqlOrder;
|
||||
}
|
||||
|
||||
if (m_sqlUserOrder == null) {
|
||||
m_sqlUserOrder = getUserOrderClause (indexOrderColumn);
|
||||
}
|
||||
|
@ -2296,24 +2323,26 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
|||
}
|
||||
}
|
||||
|
||||
protected void correctHeaderOrderIndicator() {
|
||||
Listhead listHead = contentPanel.getListHead();
|
||||
if (listHead != null) {
|
||||
List<?> headers = listHead.getChildren();
|
||||
for(Object obj : headers)
|
||||
{
|
||||
Listheader header = (Listheader) obj;
|
||||
// idempiere use mix method. sometime call model method, sometime call component method
|
||||
// so index can be difference on complicate case, just wait to fix
|
||||
if (header.getColumnIndex() == indexOrderColumn)
|
||||
header.setSortDirection(isColumnSortAscending?"ascending":"descending");
|
||||
else
|
||||
header.setSortDirection("natural");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onQueryCallback(Event event)
|
||||
{
|
||||
try
|
||||
{
|
||||
Listhead listHead = contentPanel.getListHead();
|
||||
if (listHead != null) {
|
||||
List<?> headers = listHead.getChildren();
|
||||
for(Object obj : headers)
|
||||
{
|
||||
Listheader header = (Listheader) obj;
|
||||
// idempiere use mix method. sometime call model method, sometime call component method
|
||||
// so index can be difference on complicate case, just wait to fix
|
||||
if (header.getColumnIndex() == indexOrderColumn)
|
||||
header.setSortDirection(isColumnSortAscending?"ascending":"descending");
|
||||
else
|
||||
header.setSortDirection("natural");
|
||||
}
|
||||
}
|
||||
// m_sqlUserOrder="";
|
||||
// event == null mean direct call from reset button
|
||||
if (event == null)
|
||||
|
@ -2321,7 +2350,10 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
|||
else
|
||||
executeQuery();
|
||||
|
||||
renderItems();
|
||||
renderItems();
|
||||
|
||||
correctHeaderOrderIndicator();
|
||||
|
||||
// IDEMPIERE-1334 after refresh, restore prev selected item start
|
||||
// just evaluate display logic of process button when requery by use click requery button
|
||||
if (isQueryByUser){
|
||||
|
@ -2454,6 +2486,7 @@ public abstract class InfoPanel extends Window implements EventListener<Event>,
|
|||
int col = lsc.getColumnIndex();
|
||||
indexOrderColumn = col;
|
||||
isColumnSortAscending = ascending;
|
||||
sqlOrderColumn = p_layout[col].getColSQL().trim();
|
||||
m_sqlUserOrder = null; // clear cache value
|
||||
|
||||
if (m_useDatabasePaging)
|
||||
|
|
Loading…
Reference in New Issue