1003581 IDEMPIERE-1584 -- Custom sort order is lost when updating a record.

This commit is contained in:
Heng Sin Low 2013-12-17 18:04:50 +08:00
parent b58546521f
commit 0e6d317e2b
2 changed files with 65 additions and 5 deletions

View File

@ -101,7 +101,7 @@ public class GridTable extends AbstractTableModel
/** /**
* *
*/ */
private static final long serialVersionUID = -2181155164268688340L; private static final long serialVersionUID = 4223765688790104180L;
public static final String DATA_REFRESH_MESSAGE = "Refreshed"; public static final String DATA_REFRESH_MESSAGE = "Refreshed";
@ -232,6 +232,10 @@ public class GridTable extends AbstractTableModel
private final static Integer NEW_ROW_ID = Integer.valueOf(-1); private final static Integer NEW_ROW_ID = Integer.valueOf(-1);
private static final int DEFAULT_FETCH_SIZE = 200; private static final int DEFAULT_FETCH_SIZE = 200;
/** Keep track of last sorted column index and sort direction */
private int m_lastSortColumnIndex = -1;
private boolean m_lastSortedAscending = true;
/** /**
* Set Table Name * Set Table Name
* @param newTableName table name * @param newTableName table name
@ -890,6 +894,13 @@ public class GridTable extends AbstractTableModel
} }
if (getRowCount() == 0) if (getRowCount() == 0)
return; return;
boolean isSameSortEntries = (col == m_lastSortColumnIndex && ascending == m_lastSortedAscending);
if (!isSameSortEntries)
{
m_lastSortColumnIndex = col;
m_lastSortedAscending = ascending;
}
//cache changed row //cache changed row
Object[] changedRow = m_rowChanged >= 0 ? getDataAtRow(m_rowChanged) : null; Object[] changedRow = m_rowChanged >= 0 ? getDataAtRow(m_rowChanged) : null;
@ -948,10 +959,14 @@ public class GridTable extends AbstractTableModel
m_sort.get(i).data = null; m_sort.get(i).data = null;
} }
} }
// update UI
fireTableDataChanged(); if (!isSameSortEntries)
// Info detected by MTab.dataStatusChanged and current row set to 0 {
fireDataStatusIEvent("Sorted", "#" + m_sort.size()); // update UI
fireTableDataChanged();
// Info detected by MTab.dataStatusChanged and current row set to 0
fireDataStatusIEvent("Sorted", "#" + m_sort.size());
}
} // sort } // sort
/** /**
@ -2919,6 +2934,11 @@ public class GridTable extends AbstractTableModel
m_changed = false; m_changed = false;
m_rowChanged = -1; m_rowChanged = -1;
m_inserting = false; m_inserting = false;
if (m_lastSortColumnIndex >= 0)
{
loadComplete();
sort(m_lastSortColumnIndex, m_lastSortedAscending);
}
fireTableDataChanged(); fireTableDataChanged();
if (fireStatusEvent) if (fireStatusEvent)
fireDataStatusIEvent(DATA_REFRESH_MESSAGE, ""); fireDataStatusIEvent(DATA_REFRESH_MESSAGE, "");
@ -3842,4 +3862,12 @@ public class GridTable extends AbstractTableModel
public String get_TrxName() { public String get_TrxName() {
return m_trxName; return m_trxName;
} }
/**
* reset the cache sort state ( sort column and sort ascending )
*/
public void resetCacheSortState() {
m_lastSortColumnIndex = -1;
m_lastSortedAscending = true;
}
} }

View File

@ -115,6 +115,7 @@ import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Column; import org.zkoss.zul.Column;
import org.zkoss.zul.Columns; import org.zkoss.zul.Columns;
import org.zkoss.zul.Div; import org.zkoss.zul.Div;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Hbox; import org.zkoss.zul.Hbox;
import org.zkoss.zul.Listitem; import org.zkoss.zul.Listitem;
import org.zkoss.zul.Menuitem; import org.zkoss.zul.Menuitem;
@ -1656,9 +1657,40 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
*/ */
public void onRefresh() public void onRefresh()
{ {
GridTab gridTab = adTabbox.getSelectedGridTab();
if (gridTab != null && gridTab.getTableModel() != null)
{
gridTab.getTableModel().resetCacheSortState();
}
Column sortColumn = findCurrentSortColumn();
onRefresh(true, false); onRefresh(true, false);
if (sortColumn != null)
{
sortColumn.setSortDirection("natural");
}
} }
private Column findCurrentSortColumn() {
IADTabpanel iadtabpanel = getADTab().getSelectedTabpanel();
if (iadtabpanel instanceof ADTabpanel) {
ADTabpanel adtabpanel = (ADTabpanel) iadtabpanel;
Grid grid = adtabpanel.getGridView().getListbox();
Columns columns = grid.getColumns();
List<?> list = columns.getChildren();
for(int i = 0; i < list.size(); i++)
{
Component c = (Component) list.get(i);
if (c instanceof Column) {
Column column = (Column) c;
if (!"natural".equals(column.getSortDirection())) {
return column;
}
}
}
}
return null;
}
/** /**
* @see ToolbarListener#onHelp() * @see ToolbarListener#onHelp()
*/ */