GWT DataGrid getRowElement throwing IndexOutOfBoundsException after manually setting the page - gwt

This question is almost but not quite identical to GWT CellTable getRowElement throwing IndexOutOfBoundsException , however the accepted answer there is not working for me.
I am trying to get a DataGrid to display a different row and cell from the current view. Sometimes that may be on the same page, mostly not. If the row is on the current page -- either the first page or one that has been manually paged to -- then getting the row using getRowElement(rowIdx - pageStart) works, as per the answer mentioned above.
However, if the row is not on the current page, I have found no way to get the row element.
I have tried calculating the appropriate page and setting the page using SimplePager.setPage(), then trying to get the row element using either the actual row index or the page-start-based index (as well as trying the page before and the page after, just for good measure.) All fail with IndexOutOfBoundsExceptions. I have tried force-firing a RangeChangedEvent after setting the page, but that makes no difference (other than fetching that range of data twice.)
I have also tried not setting the page and trying to get the row element, but trying to get the actual index fails as one might expect as it's not on the current page, and what other index would you otherwise use?
I am using GWT 2.8.1 and running both in a Tomcat container and in SuperDevMode in Eclipse + Chrome.
What am I missing?
Thanks,
Linus
Sample log output below:
Set page from 0 to 7
scrollRow:366, scrollCol:4
currentPage:7, start: 350, size: 50
Range start: 350, length:50
getRow:366
java.lang.IndexOutOfBoundsException: Row index: 366, Row size: 2088
getRow:16
java.lang.IndexOutOfBoundsException: Row index: 16, Row size: 2088
getRow:316, // try previous page
java.lang.IndexOutOfBoundsException: Row index: 316, Row size: 2088
getRow:416, // try next page
java.lang.IndexOutOfBoundsException: Row index: 416, Row size: 2088
page:7, rowIdx:366, showRow:366, colIdx: 4 : java.lang.IndexOutOfBoundsException: Row index: 416, Row size: 2088
To give context the code that produces this is
if ( cPage != showPage ) {
GWT.log("Set page from " + cPage + " to " + showPage);
gridPager.setPage(showPage);
}
GWT.log("scrollRow:" + scrollToRow + ", scrollCol:"+ scrollToCol);
GWT.log("currentPage:"+ gridPager.getPage() + ", start: " + gridPager.getPageStart() + ", size: "+ gridPager.getPageSize());
Range range = dataGrid.getVisibleRange();
int start = range.getStart();
GWT.log("Range start: "+ range.getStart() + ", length:" + range.getLength());
TableRowElement row;
try {
int getRow = rowIdx;
GWT.log("getRow:"+getRow);
row = dataGrid.getRowElement(getRow);
} catch (IndexOutOfBoundsException iob0 ) {
GWT.log(String.valueOf(iob0));
try {
int getRow = rowIdx-start;
GWT.log("getRow:"+getRow);
row = dataGrid.getRowElement(getRow);
} catch (IndexOutOfBoundsException iob1 ) {
<snip>
TableCellElement cell = row.getCells().getItem(colIdx);
cell.scrollIntoView();

In case anyone finds themselves here:
Thomas Broyer over in the GWT Users Group set me straight:
Even though the dataGrid says it has the rows, the data pager had not actually fetched the rows.
https://groups.google.com/forum/#!topic/google-web-toolkit/7J8H8yhV_CM
I had to set up a continuation to allow the fetch to happen, then retrieve the row so I could scroll to it.

Related

How do you prevent Word Find.Execute() from going into an endless loop?

I am writing a Word add-in using .NET and VSTO. I need to search a footer for all instances of some text. I am looping with Word's Find.Execute() as shown below. It goes into an endless loop when it matches the text in a content control in a table cell in the footer. It keeps going back to the same range.
Why would this code cause an endless loop? How can I tell Word to continue searching after this point?
using Word = Microsoft.Office.Interop.Word;
...
Word.Range range = headerFooter.Range;
Word.Find find = range.Find;
while (find.Execute(FindText: wildcard,
MatchWildcards: true,
Forward: true,
Wrap: Word.WdFindWrap.wdFindStop))
{
System.Diagnostics.Trace.TraceInformation(range.Start + ", " + range.End);
}
The code gives output like this:
192, 206
192, 206
192, 206
I tried collapsing the range to the end of the match inside the loop as follows, but it still loops forever back to the original range.
{
System.Diagnostics.Trace.TraceInformation(range.Start + ", " + range.End);
range.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
}
I am running Word version Microsoft® Word for Microsoft 365 MSO (Version 2205 Build 16.0.15225.20028) 32-bit.
In this particular instance, I was able to fix the issue by advancing the range to the beginning of the next table cell. I based this on the second post in this forum thread: https://www.msofficeforums.com/word-vba/40986-infinite-loop-when-finding-styles.html
Here is the code that fixed it in this instance. It may not fix it in every situation:
using Word = Microsoft.Office.Interop.Word;
...
Word.Range range = headerFooter.Range;
Word.Find find = range.Find;
while (find.Execute(FindText: wildcard,
MatchWildcards: true,
Forward: true,
Wrap: Word.WdFindWrap.wdFindStop))
{
results.Add(range.Duplicate);
// WARNING: In skipping the remainder of the table cell,
// we could be skipping additional matches.
if (range.Information[Word.WdInformation.wdInContentControl] && range.Information[Word.WdInformation.wdWithInTable])
{
int endOfCell = range.Cells[range.Cells.Count].Range.End;
range.End = endOfCell;
range.Start = endOfCell;
if (range.Information[Word.WdInformation.wdAtEndOfRowMarker])
{
range.End += 1;
range.Start += 1;
}
}
}

Clear Contents of Specific Ranges

I am still new to VBA. I wanted to clear all the contents of the data (Row 3 to Row 12, Row 15 to Row 24, etc) below the yellow headers, without deleting all of the headers as shown in the photos (Fig 1 becomes Fig. 2). The headers go all the way down to row 109 (increments of 12 from Row 1, so Rows 1,13,25 ...85). I have a code but its too basic and long:
Sub Clear_All()
Set Unitsheet = ThisWorkbook.Worksheets("Sheet"1)
Unitsheet.Range("A3:F12").ClearContents
Unitsheet.Range("A15:F24").ClearContents
.
.
.
.'up to
Unitsheet.Range("A111:F120").ClearContents
End Sub
I need a code that is short, since the rows may reach up to more than 1000.
Any help will be much appreciated.
|
|
V
Sub clear()
Dim i, rows As Long
rows = ActiveSheet.UsedRange.rows.Count
For i = 1 To rows
If Sheet1.Cells(i, 1).Interior.ColorIndex = -4142 Then
Sheet1.Cells(i, 1).EntireRow.ClearContents
End If
Next
End Sub
this function finds all used rows in sheet1
it iterates all rows , if color of cell in A column has no color index (-4142) it clears all contents in entire row

Office.js Word Add-In: Performance Issue with Updating Values in Large Tables

Summary:
Updating values in large Word tables (larger than 10 by 10) is very slow.
Performance gets exponentially worse with table size.
I'm using myTable.values = arrNewValues. I've also tried
myTable.addRows("end", rows, arrNewValues). Where arrNewValues is a
2D array.
I've also tried using updating via getOoxml() and
insertOoxml(), but ran into other issues I haven't been able to
resolve, but has good performance.
Slow performance seems to be caused by "ScreenUpdating" (same issue exists in VBA and is solved via ScreenUpdating=false). I believe it is critically important to add the ability to temporarily turn off ScreenUpdating.
Is there another way to improve table updating performance?
Background:
My add-in (https://analysisplace.com/Solutions/Document-Automation) performs document automation (updates content in a variety of Word docs). Many customers want to be able to update text in largish tables. Some documents have dozens of tables (appendices). I have run into the issue where updating these documents is unacceptably slow (well over a minute) due to the table updates.
Update time by table size:
2 rows by 10 columns: .33 seconds
4 rows by 10 columns: .52 seconds
8 rows by 10 columns: 1.5 seconds
16 rows by 10 columns: 5.5 seconds
32 rows by 10 columns: 20.8 seconds
64 rows by 10 columns: 88 seconds
Sample Office.js Code (Script Lab):
function updateTableCells() {
Word.run(function (context) {
var arrValues = context.document.body.tables.getFirst().load("values");
return context.sync().then(
function () {
var rows = arrValues.values.length;
var cols = arrValues.values[0].length;
console.log(getTimeElapsed() + "rows " + rows + "cols " + cols);
var arrNewValues = [];
for (var row = 0; row < rows; row++) {
arrNewValues[row] = [];
for (var col = 0; col < cols; col++) {
arrNewValues[row][col] = 'r' + row + ':c' + col;
}
}
console.log(getTimeElapsed() + 'Before setValues ') ;
context.document.body.tables.getFirst().values = arrNewValues;
return context.sync().then(
function () {
console.log(getTimeElapsed() + "Done");
});
});
})
.catch(OfficeHelpers.Utilities.log);
}
Sample Word VBA Code:
VBA performance is similar to the Office.js performance without ScreenUpdating = False. With ScreenUpdating = False, performance is instant.
Sub PopulateTable()
Application.ScreenUpdating = False
Dim nrRow As Long, nrCol As Long
Dim tbl As Word.Table
Set tbl = ThisDocument.Tables(1)
For nrRow = 1 To 32
For nrCol = 1 To 10
tbl.Cell(nrRow, nrCol).Range.Text = "c" & nrRow & ":" & nrCol
Next nrCol
Next nrRow
End Sub
Article explaining slow performance: see "Improving Performance When Automating Tables": https://msdn.microsoft.com/en-us/library/aa537149(v=office.11).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-3
Posts indicating there is no "ScreenUpdating = False" in Office.js: ScreenUpdating Office-js taskpane and Equivalent to Application.ScreenUpdating Property in office-js Excel add-in
Sounds like we won't see it any time soon.
Post related to the updating tables via getOoxml() and insertOoxml(): Word Office.js: issues with updating tables in ContentControls using getOoxml() and insertOoxml()
This is probably not the answer you're looking for, but I have been working with a word add in for validation of software, and we are talking about updating 500-1000 rows with lots of little formatting changes.
Anyway one thing I found that helped is to scroll somewhere else in the document before you make the changes to the table. Just the act of looking at it will slow it down 10-20x. It's not always instant but near.

Swift - Reload the last 20 rows in A UITableView

I'm working on a news page in an app and am attempting to reload the last 20 rows in a TableView controller whenever a fetch request is made to our API. Results are loaded in batches of 20, and I'd prefer not to reload the whole TableView whenever 20 more results are added to the table, as this causes flickering on fast scrolling.
I know I should use self.tableView.reloadRowsAtIndexPaths(), but I'm not sure as to how I obtain the index paths of last 20 rows in the table.
Use a for loop...
if there are 30 rows, this method will reload the last 20 rows (row 10 - 30). Remember, the index paths start at row 0 not 1.
for (var i = 9; i < 29; i++) {
self.tableView.reloadRowsAtIndexPaths(i)
}

In gwt , what is the simplest code to count total of rows in a celltable?

Given:
CellTable<List<String>> table = new CellTable<List<String>>();
ListDataProvider<List<String>> dataProvider = new ListDataProvider<List<String>>();
dataProvider.addDataDisplay(table);
List<List<String>> list = dataProvider.getList();
what is the simplest code to count total of rows in a celltable?
if getRowCount not working , why dont you try to get the size of the array u have , you must be pushing some array in the celltable , why don't just get the size of array ..
getRowCount() ??
Get the total count of all rows.
getVisibleItemCount()
Get the number of visible items being displayed. Note that this value might be less than the page size if there is not enough data to fill the page.
and also see the method getVisibleRange() which returns range oobject and then you can get by range.getLength()