Added Paging on Grid
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-widgetx@111426 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3ec3ec8cfa
commit
c9cfd22019
|
@ -74,9 +74,12 @@ import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent;
|
|||
import com.sencha.gxt.widget.core.client.event.HeaderContextMenuEvent.HeaderContextMenuHandler;
|
||||
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.HeaderMouseDownEvent.HeaderMouseDownHandler;
|
||||
import com.sencha.gxt.widget.core.client.event.ReconfigureEvent;
|
||||
import com.sencha.gxt.widget.core.client.event.ReconfigureEvent.ReconfigureHandler;
|
||||
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
|
||||
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
|
||||
import com.sencha.gxt.widget.core.client.grid.Grid;
|
||||
import com.sencha.gxt.widget.core.client.grid.GridView;
|
||||
import com.sencha.gxt.widget.core.client.grid.filters.Filter;
|
||||
import com.sencha.gxt.widget.core.client.info.Info;
|
||||
import com.sencha.gxt.widget.core.client.menu.Item;
|
||||
|
@ -84,6 +87,7 @@ import com.sencha.gxt.widget.core.client.menu.Menu;
|
|||
import com.sencha.gxt.widget.core.client.menu.MenuItem;
|
||||
import com.sencha.gxt.widget.core.client.menu.SeparatorMenuItem;
|
||||
import com.sencha.gxt.widget.core.client.selection.CellSelection;
|
||||
import com.sencha.gxt.widget.core.client.toolbar.PagingToolBar;
|
||||
import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
|
||||
|
||||
/**
|
||||
|
@ -96,6 +100,8 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar;
|
|||
*/
|
||||
public class TabularDataXGridPanel extends ContentPanel {
|
||||
|
||||
private static final int PAGINGDIMENSION = 300;
|
||||
|
||||
private int tdSessionId;
|
||||
|
||||
private EventBus eventBus;
|
||||
|
@ -139,6 +145,10 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
private TDXLiveToolItem tdxLiveToolItem;
|
||||
|
||||
private PagingToolBar pagingToolBar;
|
||||
|
||||
private FilterPagingLoadConfig lastFilterPagingLoadConfig;
|
||||
|
||||
/**
|
||||
* @param eventBus
|
||||
*/
|
||||
|
@ -299,8 +309,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
for(Row row:rows) {
|
||||
for (Row row : rows) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
ColumnModel<DataRow> columnModel = grid.getColumnModel();
|
||||
List<ColumnConfig<DataRow, ?>> columns = columnModel
|
||||
|
@ -653,7 +662,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
grid.addHeaderMouseDownHandler(handler);
|
||||
}
|
||||
}
|
||||
|
@ -700,9 +709,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
columnModel = new ColumnModel<DataRow>(columnsConfig);
|
||||
|
||||
columnModel = checkOnlyColumn(columnModel);
|
||||
|
||||
|
||||
|
||||
|
||||
columnModel
|
||||
.addColumnMoveHandler(new ColumnMoveEvent.ColumnMoveHandler() {
|
||||
|
||||
|
@ -721,10 +728,13 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
+ " ColumnId: " + colDef.getColumnLocalId());
|
||||
|
||||
if (colDef.isViewColumn()) {
|
||||
Info.display("Attention", "The view columns can not be moved");
|
||||
//ColumnHeader<DataRow> colHeader=grid.getView().getHeader();
|
||||
|
||||
//event.getSource().moveColumn(columnIndex, colDef.getPosition());
|
||||
Info.display("Attention",
|
||||
"The view columns can not be moved");
|
||||
// ColumnHeader<DataRow>
|
||||
// colHeader=grid.getView().getHeader();
|
||||
|
||||
// event.getSource().moveColumn(columnIndex,
|
||||
// colDef.getPosition());
|
||||
} else {
|
||||
ColumnsReorderingConfig columnsReorderingConfig = new ColumnsReorderingConfig(
|
||||
columnIndex, colDef);
|
||||
|
@ -736,7 +746,8 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
});
|
||||
|
||||
if (grid == null) {
|
||||
Log.debug("Setup grid null");
|
||||
Log.debug("Setup reader");
|
||||
|
||||
reader = new DataRowPagingReader(tableDefinition);
|
||||
|
||||
String path = GWT.getModuleBaseURL() + "tdwxdata";
|
||||
|
@ -751,6 +762,11 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
builder);
|
||||
proxy.setWriter(new PagingLoadUrlEncoder(staticFilters));
|
||||
|
||||
if (loader != null) {
|
||||
lastFilterPagingLoadConfig = loader.getLastLoadConfig();
|
||||
|
||||
}
|
||||
|
||||
loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<DataRow>>(
|
||||
proxy, reader) {
|
||||
@Override
|
||||
|
@ -758,48 +774,43 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
return new FilterPagingLoadConfigBean();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* HttpProxy<PagingLoadConfig> proxy = new
|
||||
* HttpProxy<PagingLoadConfig>( builder); proxy.setWriter(new
|
||||
* PagingLoadUrlEncoder());
|
||||
*
|
||||
* loader = new PagingLoader<PagingLoadConfig,
|
||||
* PagingLoadResult<DataRow>>( proxy, reader) {
|
||||
*
|
||||
* @Override protected PagingLoadConfig newLoadConfig() { return new
|
||||
* PagingLoadConfigBean(); } };
|
||||
*/
|
||||
|
||||
loader.setRemoteSort(true);
|
||||
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<FilterPagingLoadConfig, DataRow, PagingLoadResult<DataRow>>(
|
||||
store));
|
||||
|
||||
liveGridView = new ExtendedLiveGridView<DataRow>();
|
||||
pagingToolBar = new PagingToolBar(PAGINGDIMENSION);
|
||||
pagingToolBar.getElement().getStyle()
|
||||
.setProperty("borderBottom", "none");
|
||||
pagingToolBar.bind(loader);
|
||||
|
||||
// gridView = new ExtendedGridView<DataRow>();
|
||||
|
||||
// liveGridView = new ExtendedLiveGridView<DataRow>();
|
||||
// liveGridView.setRowHeight(19);
|
||||
|
||||
grid = new Grid<DataRow>(store, columnModel);
|
||||
grid = new Grid<DataRow>(store, columnModel) {
|
||||
@Override
|
||||
protected void onAfterFirstAttach() {
|
||||
super.onAfterFirstAttach();
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
loader.load();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
sm = new GridAndCellSelectionModel<DataRow>();
|
||||
|
||||
grid.setSelectionModel(sm);
|
||||
grid.setLoadMask(true);
|
||||
grid.setLoader(loader);
|
||||
grid.setView(liveGridView);
|
||||
// grid.setView(gridView);
|
||||
// grid.setView(liveGridView);
|
||||
grid.setBorders(false);
|
||||
grid.setColumnReordering(true);
|
||||
|
||||
// TODO disabled editing rows
|
||||
/*
|
||||
* editing = new GridInlineEditing<DataRow>(grid);
|
||||
* editing.setClicksToEdit(ClicksToEdit.TWO);
|
||||
*
|
||||
* for (ColumnConfig<DataRow, ?> c : columnsConfig) {
|
||||
* ColumnConfigGenerator.setEditor(editing, c); }
|
||||
*/
|
||||
|
||||
// numberer.initPlugin(grid);
|
||||
|
||||
// Filter
|
||||
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
||||
|
@ -815,22 +826,23 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
//
|
||||
container.add(grid, new VerticalLayoutData(1, 1, new Margins(0)));
|
||||
container.add(pagingToolBar, new VerticalLayoutData(1, -1));
|
||||
|
||||
toolBar = new ToolBar();
|
||||
// toolBar.add(new LiveToolItem(grid));
|
||||
tdxLiveToolItem = new TDXLiveToolItem(grid);
|
||||
|
||||
toolBar.add(tdxLiveToolItem);
|
||||
toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||
toolBar.getElement().getStyle().setProperty("borderBottom", "none");
|
||||
|
||||
container.add(toolBar,
|
||||
new VerticalLayoutData(1, 24, new Margins(0)));
|
||||
|
||||
container.forceLayout();
|
||||
|
||||
loader.load(0, liveGridView.getCacheSize());
|
||||
/*
|
||||
* toolBar = new ToolBar(); tdxLiveToolItem = new
|
||||
* TDXLiveToolItem(grid);
|
||||
*
|
||||
* toolBar.add(tdxLiveToolItem);
|
||||
* toolBar.addStyleName(ThemeStyles.get().style().borderTop());
|
||||
* toolBar.getElement().getStyle().setProperty("borderBottom",
|
||||
* "none");
|
||||
*
|
||||
* container.add(toolBar, new VerticalLayoutData(1, 24, new
|
||||
* Margins(0)));
|
||||
*/
|
||||
// container.forceLayout();
|
||||
|
||||
// loader.load(0, liveGridView.getCacheSize());
|
||||
if (contextMenu != null) {
|
||||
grid.setContextMenu(contextMenu);
|
||||
} else
|
||||
|
@ -842,37 +854,36 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
} else {
|
||||
Log.debug("Setup grid not null");
|
||||
// TODO we need to manually reset the sort
|
||||
sm.onChangeNumberOfRows();
|
||||
tdxLiveToolItem.setNoSelected();
|
||||
// sm.onChangeNumberOfRows();
|
||||
// tdxLiveToolItem.setNoSelected();
|
||||
|
||||
loader.clearSortInfo();
|
||||
reader.setDefinition(tableDefinition);
|
||||
grid.reconfigure(store, columnModel);
|
||||
loader.clearSortInfo();
|
||||
|
||||
loader.addLoadHandler(new LoadResultListStoreBinding<FilterPagingLoadConfig, DataRow, PagingLoadResult<DataRow>>(
|
||||
store));
|
||||
|
||||
grid.reconfigure(store, columnModel);
|
||||
// grid.setLoader(loader);
|
||||
// pagingToolBar.bind(loader);
|
||||
|
||||
// Filter
|
||||
ArrayList<Filter<DataRow, ?>> filters = FiltersGenerator
|
||||
.generate(columnModel);
|
||||
gridFilters.removeAll();
|
||||
|
||||
// gridFilters = new ExtendedGridFilters<DataRow>(loader);
|
||||
|
||||
// gridFilters.initPlugin(grid);
|
||||
// gridFilters.setLocal(false);
|
||||
|
||||
Log.debug("Filters: " + filters.size());
|
||||
for (Filter<DataRow, ?> filterGeneric : filters) {
|
||||
gridFilters.addFilter(filterGeneric);
|
||||
}
|
||||
|
||||
// TODO Disabled editing rows
|
||||
//
|
||||
// editing = new GridInlineEditing<DataRow>(grid);
|
||||
// editing.setClicksToEdit(ClicksToEdit.TWO);
|
||||
//
|
||||
// for (ColumnConfig<DataRow, ?> c : columnsConfig) {
|
||||
// ColumnConfigGenerator.setEditor(editing, c); }
|
||||
//
|
||||
|
||||
// TODO workaround: the loader is called only if the scroll bar is
|
||||
// in the middle
|
||||
// if (loader.getOffset() == 0)
|
||||
// loader.load();
|
||||
loader.load(0, liveGridView.getCacheSize());
|
||||
loader.load();
|
||||
// lastFilterPagingLoadConfig.getOffset(),
|
||||
// lastFilterPagingLoadConfig.getLimit());
|
||||
}
|
||||
|
||||
if (tableViewConfig != null) {
|
||||
|
@ -897,13 +908,6 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
|
||||
container.forceLayout();
|
||||
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
|
||||
public void execute() {
|
||||
container.forceLayout();
|
||||
}
|
||||
});
|
||||
|
||||
eventBus.fireEvent(new GridReadyEvent());
|
||||
|
||||
}
|
||||
|
@ -967,6 +971,7 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
}
|
||||
};
|
||||
Log.debug("Created Handler");
|
||||
|
||||
grid.addHeaderContextMenuHandler(headerContextMenuHandler);
|
||||
Log.debug("Header Column Menu Added");
|
||||
|
||||
|
@ -1016,20 +1021,4 @@ public class TabularDataXGridPanel extends ContentPanel {
|
|||
return columnLocalId;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disabled AddROW by direct editing
|
||||
*
|
||||
* public void addRow(ArrayList<String> rows) {
|
||||
*
|
||||
* if (grid != null && editing != null) { List<ColumnKey> keys =
|
||||
* tableDefinition.getKeys(); DataRow dataRow = new DataRow(keys.size());
|
||||
* for (ColumnKey key : keys) { dataRow.set(key, null); }
|
||||
* editing.cancelEditing(); int pos = 0; if (rows != null && rows.size() >
|
||||
* 0) { pos = new Integer(rows.get(0)); } store.add(pos, dataRow);
|
||||
*
|
||||
* int row = store.indexOf(dataRow); editing.startEditing(new GridCell(row,
|
||||
* pos)); }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ public class ExtendedGridFilters<M> extends GridFilters<M> {
|
|||
private SeparatorMenuItem separatorItem;
|
||||
private CheckMenuItem checkFilterItem;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates grid filters to be applied remotely. See
|
||||
* {@link AbstractGridFilters#AbstractGridFilters(Loader)} for more
|
||||
|
|
|
@ -136,7 +136,7 @@ public class RequestData implements Serializable {
|
|||
|
||||
|
||||
/*
|
||||
* { "limit": "200",
|
||||
* { "limit": "1000",
|
||||
* "offset": "330",
|
||||
* "filters": [
|
||||
* { "filterField":"kqljyp" ,"filterType":"date" ,"filterComparison":"on" ,"filterValue": "1399370400000" },
|
||||
|
|
Loading…
Reference in New Issue