GWT CellTable - Column Sorting is reset after ListDataProvider refresh - gwt

I'm using a CellTable, which is fed data via a ListDataProvider. Currently a user can sort the CellTable columns, then click a row. Clicking a row pops up a stand alone editor next to the cell table. When the user clicks "save", the code updates the employee in the ListDataProvider, then calls:
listDataProvider.refresh();
This works, but the column sort is reset. This is not acceptable because it resets the column sort that they have used, and it is a pain to have to resort the columns after every save. Is there some way to tell the CellTable to keep its current column sort when refresh is called?

Your need to call ColumnSortEvent.fire(dataGrid, dataGrid.getColumnSortList()); if you want to recover the sort order after refresh. I think it should work the same for CellTable.
This is how we refresh the DataGrid:
selectionModel.clear(); // SingleSelectionModel
dataList.clear(); // List<Data>
dataList.addAll(newData); // List<Data>
dataProvider.flush(); // ListDataProvider<Data>
dataProvider.refresh();
ColumnSortEvent.fire(dataGrid, dataGrid.getColumnSortList()); // DataGrid<Data>

Ended up adding a listener on the column sort, and sorted the list in code rather than allowing the CellTable to handle the sort. This kept the sort order. I'd post the code, but I no longer have access to the code base.

Related

Add empty rows in a tableviewer

I want to use a "Add" button to add empty rows in the table using table viewer. After adding a new row, the user can edit it. How can I implement this design? Thanks!
You should add the rows to the data that your content provider returns in the getElements method using something that the label provider will show as empty. You then call refresh on the table.
For editing you will use the normal EditingSupport and make sure it can deal with empty entries.

Updating slickgrid autocomplete fields without rerendering the grid

I'm using SlickGrid in a sharepoint environment to display and update data. To save on the the load time, I am populating auto complete fields with options that have only been used in previous lines (with tables with more than 50 lines), and then I am wanting to give the user the option to click on a "Metadata refresh button" located at the top of the autocomplete fields that will go and fetch all available options to repopulate the auto complete field.
<table><tr><td>[ TextField ] </td><td>[ AutoComplete1 ] </td><td>[ AutoComplete2]</td></tr>
<tr><td>Entry1</td><td>Hello</td><td>Goodbye</td></tr>
<tr><td>Entry2</td><td>Hi</td><td>Later</td></tr>
</table>
So if, the user was to create a new line, they would have the options of Hello and Hi in column 2, and Goodbye or Later in column 3 to choose from since they have been used before. If they want the option "Hail!" to appear in column 2, they would have to click the "Update MetaData" button for column 2, which would refresh ALL the cells in that column with all available but previously unused selections.
I know its not ideal, but its a requirement that has been given to me.
I know how to add buttons to column headers and I am updating the array of data that the grid needs for the autocomplete column, but I am at a loss on how to update the column choices without redrawing the whole grid.
Any suggestions?
Check out the newer examples in my repo: https://github.com/6pac/SlickGrid/wiki/Examples
This is probably closest to what you want:
http://6pac.github.io/SlickGrid/examples/example-autocomplete-editor.html
What I have done in the past is create a data property of the cell node to store the object, like:
$jqacContainer.data('queryautocomplete', jqac);
It's then easy enough to get the object from the cell node.
However, this requires proper cleanup of the property to avoid a memory leak. This should be able to be done in editor.destroy(), but I don't think I've checked corner cases, for example where the editor is scrolled offscreen before being completed.

GWT: get backing object for row by id in table

Is there any simple way to get the object, used to render given row in CellTable, by index of the row?
I am using AsyncDataProvider, and don't want to remember lists of data objects, returned from the server. Also I am using MultiSelectionModel, so several items could be selected there and I need to track out which one was clicked last.
I know the index of last clicked row, so I need to get the object, corresponding to the row, somehow.
getVisibleItem? possibly combined with getPageStart if you're using paging and you only know the absolute index.
For your use-case, maybe you could use a customized selection model whose setSelected tracks the last change.

Inserting rows in form datasource, insert is OK, rows are not visible

Basically, I want to insert rows in the form InventJournalTransfer. I added a menuitem button that calls a class which opens a dialog where I fill a WMSLocationId, then I loop on Inventsum table to get all ItemIds with Available qty for this WMSLocationId and insert them into InventJournalTrans Table.
The code I wrote seems to be working as I have correct records inserted in my table(visible in Table browser, correct journalId, linenum itemId, qty etc...) BUT the records inserted do not appear in my form. I tried to refresh my form with or without code, but my grid's still empty.
I had a look at the class InventCountCreate that does what I want to do in a different journal type, but as I'm quite a newbie it is difficult for me to understand exactly how this class works.
Could anyone explain to me how to display my inserted rows in my form or give other leads?
The InventJournalTrans is table is inner joined to two InventDim, one related via the InventDimId field, the other via ToInventDimId.
Both fields must be filled with a valid InventDimId to an existing InventDim record for the form to show the record.
Have you tried right-clicking on your form's node in the AOT and clicking "Restore"? Perhaps your form is still using cached data.

How to Force a Sorting in a SWT Table w/ Table Viewer

I want to sort, only for the first time, a SWT Table column.
I have a Table with their TableViewer and I want to Sort programmaticaly after or before setInput Method.
The columns are dynamically generated, and the last ones is an average column.
Is there any way of Sorting by program?
I'm using only this line of code:
columnPromEcr = new TableColumn(table, SWT.RIGHT);
columnPromEcr.setText("Prom. ECR");
columnPromEcr.pack();
columnPromEcr.setResizable(true);
this.table.setSortColumn(columnPromEcr);
After setInput method I call:
// refresh table
tableViewer.refresh();
table.setRedraw(true);
Do I need a class ViewerSorter?
I don't need user intervention, my data came unordered, and after creating a dynamic column I want the program to order the table with that info, numeric data.
You don't need ViewerSorter if you only want to sort items before they are displayed. Use Comparator and Collections.sort().
Yes, use a ViewerSorter, it will keep the TableViewer in order all the time.
If u want the default behavior for sorting(integer,string simple comparison) you can just set the sorter:
viewer.setSorter(new ViewerSorter());
and the viewer will be sorted all the time (e.g. after deletions,additions of data)