How to force cellTable to show all data (GWT)? - gwt

Here I have itemDetailTable
CellTable<List<String>> itemDetailTable = new CellTable<List<String>>();
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDataDisplay(itemDetailTable);
final ScrollPanel itemDetailScrollPanel=new ScrollPanel();
FlowPanel itemDetailFlowPanel=new FlowPanel();
itemDetailFlowPanel.add(itemDetailTable);
itemDetailScrollPanel.add(itemDetailFlowPanel);
Now my List<List<String>> has 16 rows, however, after ran it showed the table with 15 rows only. If I want to see the row 16 then need to click on the last cell of the table (the cell in the bottom right handside of the table) & enter arrow-down key then it will show the record 16.
If i use Simplepager
SimplePager itemDetailPager = new SimplePager();
itemDetailPager.setDisplay(itemDetailTable);
then it will have 2 page, the 1st page has 15 records and the 2nd page has 1 record.
That is not OK as I want the table to show all the records at once and won't hide any records.
Someone said that maybe cos I use List<String> & that is causing the problem, but I am not sure if that is the main cause.
But If I only has 14 records, then it showed all 14 records without any problem.
SO How to fix it?

Try any one
Just pass page size while constructing CellTable that constructs a table with the given page size.
int pageSize=16;
CellTable<List<String>> itemDetailTable = new CellTable<List<String>>(pageSize);
use CellTable#setPageSize() to set the number of rows per page and refresh the view.
CellTable<List<String>> itemDetailTable = new CellTable<List<String>>();
itemDetailTable.setPageSize(16);
Note: use GWT.create() to construct the SimplePager.Resources object with as shown below:
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
// pass the parameters as per your requirement
SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);

Related

NatTable - Strange behavior when sorting

I have a nattable with sort/filter capabilities based off of
http://www.eclipse.org/nattable/documentation.php?page=sorting
and example 6031_GlazedListsFilterExample.java
Initially my table has zero rows.
Scenario 1:
I view a CTabItem that contains a NatTable with no rows.
If I then populate the rows and click on the column headers, nothing happens (sorting seems disabled).
Scenario 2:
I do NOT view a CTabItem that contains the NatTable with no rows.
I then populate the rows
I then view the CTabItem that contains the NatTable which now has rows.
I click on the column headers and everything sorts as expected (sorting seems enabled)
Scenario 3:
I do NOT view a CTabItem that contains the NatTable with no rows.
I then populate the rows
I then view the CTabItem that contains the NatTable which now has rows.
I then remove all row data
I click on the column headers and everything sorts as expected (sorting seems enabled). * even though there are no rows I still see the up/down icons appear in the column header cell
Is there a reason that the column header actions are not 'updated' after the initial 'view' of the NatTable? In other words, it seems to take the presence/absence of rows into account for the rest of the tables life after the first time the NatTable is viewed, regardless of if the rows change.
Relevant Code sections shown below:
private CompositeLayer createExampleLayer(Collection<T> values,
IColumnPropertyAccessor<T> columnPropertyAccessor,
IDataProvider columnHeaderDataProvider, IConfigRegistry
configRegistry, Matcher<T> matcher) {
BodyLayerStack<T> bodyLayerStack = new BodyLayerStack<>(
values, columnPropertyAccessor);
// build the column header layer
DataLayer columnHeaderDataLayer = new
DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new
ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack,
bodyLayerStack.getSelectionLayer());
SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<>
(columnHeaderLayer, new GlazedListsSortModel<T>
(bodyLayerStack.getSortedList(), columnPropertyAccessor,
configRegistry,
bodyLayerStack.getBodyDataLayer()), false);
FilterRowHeaderComposite<T> filterRowHeaderLayer = new
FilterRowHeaderComposite<>(
new DefaultGlazedListsFilterStrategy<T>
(bodyLayerStack.getFilterList(), columnPropertyAccessor,
configRegistry),
sortHeaderLayer, columnHeaderDataLayer.getDataProvider(),
configRegistry);
// Omitted code for rowHeaderLayer and cornerLayer
return new GridLayer(bodyLayerStack, filterRowHeaderLayer,
rowHeaderLayer, cornerLayer);
}
public BodyLayerStack(Collection<T> values,
IColumnPropertyAccessor<T> columnPropertyAccessor) {
eventList = GlazedLists.eventList(values);
TransformedList<T, T> rowObjectsGlazedList =
GlazedLists.threadSafeList(eventList);
this.sortedList = new SortedList<>(rowObjectsGlazedList, null);
// wrap the SortedList with the FilterList
this.filterList = new FilterList<>(sortedList);
this.bodyDataProvider = new ListDataProvider<>(this.filterList,
columnPropertyAccessor);
this.bodyDataLayer = new DataLayer(getBodyDataProvider());
// layer for event handling of GlazedLists and PropertyChanges
GlazedListsEventLayer<T> glazedListsEventLayer = new
GlazedListsEventLayer<>(bodyDataLayer, this.filterList);
this.selectionLayer = new SelectionLayer(glazedListsEventLayer);
ViewportLayer viewportLayer = new ViewportLayer(getSelectionLayer());
setUnderlyingLayer(viewportLayer);
}
private void enableSorting() {
this.nattable.addConfiguration(new SingleClickSortConfiguration());
}
Looks like the creation of your SortHeaderLayer is not correct. The last parameter of the GlazedListsSortModel needs to be the IDataLayer of the column header, not the body layer.
Changing your code to the following should make things work. It did at least on my side.
SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<>
(columnHeaderLayer, new GlazedListsSortModel<T>
(bodyLayerStack.getSortedList(), columnPropertyAccessor,
configRegistry,
columnHeaderDataLayer), false);

How to implement Expand/Collapse for a table with Multiple columns - GWT - Google Visualization API

I have list of Items with parent child relation.
At present I am displaying them in a single table. In each row, fist column starts with number of '-'s indicating the depth.
Now I want show only top level items first and with a '+' button before that.
When the user clicks on the '+' button it should turn to '-' and the children of that particular Item need to be displayed.
So, Please help me how to implement that Expand and Collapse functionality in GWT.
EDIT:
I have my Items in a tree format.
Now I am creating a DataTable and Displaying it using GoogleTableChart
The code as follows:
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Item Name ");
data.addColumn(ColumnType.STRING, "Item Id");
data.addColumn(ColumnType.NUMBER, "Quantity");
data.addColumn(ColumnType.NUMBER, "Price ($)");
data.addRows(treeList.size());
int i=0;
while(i<treeList.preOrderTraversal().size())
{
int col=0;
Item d=(Item) treeList.preOrderTraversal().get(i);
int level=d.getLevel();
//setting values to DataTable goes here
i++;
}
GoogleTableChart tblChart = new GoogleTableChart();
vPanel.add(tblChart.showFlexibleTable1(data));
Here is my solution:
I create Nested VertialPanels for each Item. And put the reference in a map.
Hide/unhide the panels based on clicks.
For root Item take one panel and add all its children.
After adding one child, add all its children to another panel,hide it and add to root panel.
repeat the steps recursively.
before each row place put (+/-) label and add click handler which take item id as parameter.
when these lables are clicked, based on the status we hide/unhide the panels, taken from the map.
Any Better Solution ... ??

Smart GWT listgrid, how to expand and row span at the same time

So I have a Smart GWT ListGrid and I want to be able to make the rows expandable and at the same time do a row span on them. Expanding rows which are not merged (by doing row span) works fine, however if I have several rows that are merged the expand icon disappears. My code for expanding and row spanning is this:
lisgrid = new LisGrid()
{
#Override
protected Canvas getExpansionComponent(final ListGridRecord record)
{
// Add a nested grid to display the remaining requests for the tag
// (after the first N being shown be default).
VLayout layout = new VLayout(5);
layout.setPadding(1);
final ExtendedListGrid requestGrid = new ExtendedListGrid();
requestGrid.setWidth(500);
requestGrid.setHeight(224);
requestGrid.setCellHeight(22);
requestGrid.setDataSource(datasource);
requestGrid.fetchData();
layout.addMember(requestGrid);
return layout;
}
};
listGrid.setAllowRowSpanning(true);
listGrid.setCanExpandRecords(true);
listGrid.setMergeCols(new String[] { "requestSummaryTagId", "gca" });
I have overridden the getRowSpan method of the ListGrid to span a cell until the cell right under (same column index and next row index) it has the same value, and I also have a method, setMergeCols, that tells the grid which cells to span across rows. Here is what it looks like. As you can see, the first 2 cells at the bottom span 4 rows, but the expand symbol is missing, while for the rows above (which don't have any row span) the expand symbol is there. Any idea why?

GWT CellTable keep focus on selected row

When I select a row in a CellTable which contains several columns, the whole row gets colored in yellow. It does not depend on which area of the row I click (which column of the row).
What I try to do is to keep the selected row colored in yellow as long as no other row of this very table is selected. At the moment, as soon as I click somewhere else in the browser, the row gets back its original color.
I tried to use a selection model, but this changed nothing. Do you have any advise or is this simply not possible, since the focus is managed by the browser? The behavior is the same in the Google showcase for the CellTable...
The selection model actually does what you want to do: it paints a row blue and the row does not change color if you click elsewhere in the page. (Only when another row is selected)
There are 2 selection models:
One that lets you select only one row, and another one that lets you select multiple rows.
MultiSelectionModel<Row> selectionModel = new MultiSelectionModel<Row>();
table.setSelectionModel(selectionModel);
SingleSelectionModel<Row> selectionModel = new SingleSelectionModel<Row>();
table.setSelectionModel(selectionModel);
The solution of user905374 did actually work. I mentioned in my first post that I already tried the solution with a selectionModel and that it did not work. This was partially true. It does work, but only if the table does NOT contain a CheckboxCell.
Following a working and the not working example. I think this might be a bug, but I am not sure if I miss something.
final CellTable<LicenceDto> licenseTable = new CellTable<LicenceDto>();
final SingleSelectionModel<LicenceDto> selectionModel = new SingleSelectionModel<LicenceDto>();
licenseTable.setSelectionModel(selectionModel);
//--- If I add this column, the selection does work.
Column<LicenceDto, String> workingColumn = new Column<LicenceDto, String>(new TextCell()) {
#Override
public String getValue(LicenceDto object) {
return "Works";
}
};
workingColumn.setFieldUpdater(new FieldUpdater<LicenceDto, String>() {
#Override
public void update(int index, LicenceDto object, String value) {
;
}
});
licenseTable.addColumn(workingColumn);
//--- If I add this column, the selection does NOT work anymore.
Column<LicenceDto, Boolean> notWorkingColumn = new Column<LicenceDto, Boolean>(new CheckboxCell(true, true)) {
#Override
public Boolean getValue(LicenceDto object) {
return object.getEnabled();
}
};
notWorkingColumn.setFieldUpdater(new FieldUpdater<LicenceDto, Boolean>() {
#Override
public void update(int index, LicenceDto object, Boolean value) {
presenter.enableLicense(object, value);
}
});
licenseTable.addColumn(notWorkingColumn);
You can even combine multiple cells and add them to the table (e.g. LinkActionCell etc). As long as there is no CheckboxCell, the blue selection with the SingleSelectionModel does work like a charm. Does anyone see what I do wrong with this CheckboxCell or is there a bug?
UPDATE
It was simply a usage error of me. The problem was that I set handlesSelection to true (second parameter of the CheckboxCell constructor) even thought I don't handle anything. Setting it to false solves the problem.
Bottomline: Use a selection model (e.g. SingleSelectionModel) and do not set the handlesSelection parameter to true of the CheckboxCell constructor to true, if you don't handle the selection by yourself.
You should observe the Showcase demo again. This time use the checkbox on the left most column i.e the first column. On selection the row turns blue indicating the row selection is made. This is when you have SelectionModel set up. Click on the page anywhere outside the CellTable/DataGrid the selection is not changed.
Now, instead of choosing the row via checkbox from first column, you click on a row in any other column. The row turns yellow. Click on the page anywhere outside the CellTable/DataGrid the focus/yellow is lost.
"colored in yellow" indicates row is under focus and being edited and not selected.
Note - you can force row selection by using click events per cell.
Try something like this:
CellTable table;
YourDataObject object = new YourDataObject(...);
SingleSelectionModel<YourDataObject> selectionModel =
new SingleSelectionModel<YourDataObject>();
table.setSelectionModel(selectionModel);
...
table.setSelected(object, true);
Use MultiSelectionModel if you wish more than one line to be highlighted.
Store the selected row's index. When user selects row, change row's style to some "selected-style" appropriate for your case (defined in your css file) and remove selected style from the previously selected row. Also don't forget to update selected row's index.
If you provide some code from the original version I help you out with some code with pleasure.

make the gwt celltable row selected

I have a cell Table in GWT with columns , there are 3 rows in each column, I want the first row to get selected by default when the application starts
some thing like this
mycelltable.setselectedrow(index);
is it possible ?
Thanks
her is the code
display.getShortListedCVsBasedOnJob().getResumeDescriptionColumn().setFieldUpdater(
new FieldUpdater<CandidateSummary, String>() {
public void update(int index, CandidateSummary object,
String value) {
fetchResume(cvSelected, shortListedFlag);
}
});
This fetchResume() method calls but only when i select cell of this column , I want to call this fetchResume() method as my application starts, i.e i want to make the 1st cell of the column to be selected byDefault.
Selection is handled by a SelectionModel, based on objects (not indices); so you have to select the first object from your data in the SelectionModel used by the CellTable (have a look at the Using a key provider to track objects as they change sample code in the Celltable javadoc for an example (last sample before nested classes summary).
This could work?
setSelected(Element elem, boolean selected)
see GWT Documentation
CellTable Google Web Toolkit
Hmm I dont see what´s the Celltable is there. I would set the initial Value like this:
int INITAL_SET_ROW = 0;
TableRowElement initalSetElement = yourCellTable.getRowElement(INITAL_SET_ROW);
yourCellTable.setSelected(initialSetElement, true);
You can try to implement it in you´re main Method. Haven´t tested it tho, hope it helps.
Simply;
List<RowType> source = new LinkedList<RowType>();
//put some data to this list
//populate the table
table.setRowCount(source.size(), true);
table.setRowData(0, source);
//for example, you can select the first row
RowType firstRow = source.get(0);
selectionModel.setSelected(firstRow, true);