How to disable cache for ag-grid when paging to previous pages - ag-grid

I'm using ag-grid with server-side row model and pagination, just the previous and next buttons, no scrolling. I want ag-grid to load data (so calling getRows()) on every click to next and previous.
It works fine for next page but the data for previous page is never loaded again from server.
I'm using this config properties for pagination and cache:
rowModelType: 'serverSide',
pagination: true,
paginationPageSize: 10,
cacheBlockSize: 10,
maxBlocksInCache: 0
More or less completely disabling cache on client side. Any hint how to accomplish that?

Here is your solution:
maxBlocksInCache = 1;
cacheBlockSize - should be the same as paginationPageSize (cuz it would one visible 'scope' - for block storage, so remember to bind it to one property) and then - block storage is a maxBlocksInCache - should be the one only (cuz one visible block is equal to one block in cache)
rowModelType: 'serverSide',
pagination: true,
paginationPageSize: 10,
cacheBlockSize: 10,
maxBlocksInCache: 1
Demo

Related

iText7 How do I know Table flows to next page like ITextshap Column.HasMoretext?

I have a form where I have to place some fixed data on top and bottom with a variable table in between. If table does not fit on first page, there should be created more pages as needed to acomodate Table.
But for page 2, 3, 4... I still have to print top & bottom, but this time a short version of whats was placed on page 1.
In ItextSharp5 with ColumnText.HasMoreText = true, I know when a new page is needed and can make a new page with proper top & bottom data before drop remaining table.
So how can I achieve same behaviour with iText7?
I did not found a way to know when a table needs some more room
After some reading, found a starting point at Chapter 2: Adding content to a Canvas or a Document
on 3th block of code.

Is there any way/api to set a certain row to be shown at the top in ag-grid?

When I don't do/call any grid api, it, of course, displays the grid-look with the very first index row. But here what I'd like to achieve is with ag-grid is that I want to set a certain row to be shown at the top. I've tried using ensureIndexVisible api with targetIndex on the firstDataRendered event hook but it causes an awkward user experience as it scrolls down to the row after it finishes rendering. So I'm wondering if there's any other approach for this needs yet with un-awkward user experience. Here's my trying snippet:
Using Angular 7
// template
<ag-grid-angular
[rowData]="rowData"
(firstDataRendered)="onRendered()">
</ag-grid-angular>
// component
onRendered(): void {
const targetIndex = this.getTargetIndex();
this.gridOptions.api.ensureIndexVisible(targetIndex, 'top');
}
You can use Row Pinning feature of ag-grid to pin single or multiple rows to the top or bottom of the grid always.
The api to set pinned rows is setPinnedTopRowData.
this.gridApi.setPinnedTopRowData(rows);
Sample plunker which demonstrates the row pinning feature - https://plnkr.co/edit/?p=preview
Read more about row pinning in the ag-grid documentation here - https://www.ag-grid.com/javascript-grid-row-pinning/

GWT SimplePager issues

I am using GWT's (2.5) SimplePager class in my application, to display pre-loaded data (I know the exact row count in advance).
The issue is with the last page. Given I have, for instance, 42 elements with an initial visible range of 10.
First page is 1-10, second 11-20, third 21-30, fourth, 31-40.
The issue is that fifth page is not 41-42 (which I want, because I want to be able to scroll back and forth and "land" exactly on the same data) but 33-42.
I have tried various tinkering with overriding SimplePager / AbstractPager methods, with no success.
For instance, if I override setPageStart, do the same as com.google.gwt.user.cellview.client.AbstractPager.setPageStart(int) but with the following commented out (I think it is the culprit code):
if (isRangeLimited && display.isRowCountExact()) {
index = Math.min(index, display.getRowCount() - pageSize);
}
The last page is fine (41-42), but this erases page size forever and when I go from last page to previous page, it becomes 40-41 (expected: 31-40). This is probably because the page size is not some constant provided to the pager instance, but is calculated with the Range object which was last used ("int pageSize = range.getLength();" in setPageStart method).
Any clue on modifying the paging behavior to my needs without breaking anything ?
Thanks !
I eventually got a working solution which is simple enough.
I provided a page size (which is the maximum number of elements that could be displayed, regardless of the total number of elements available to display) to my SimplePager object. Then I overrided getPage(), hasNextPage(), hasNextPages(int), hasPreviousPages(int), nextPage(), previousPage(), setPageStart(int) to use the provided page size instead of getLength() on the Range object.
To test this more easily (still done by hand...) I used GWT's Showcase project (and ran it in dev mode).
The downside is that I had to copy the code of the overriden methods (from AbstractPager - SimplePager does nothing except calling the superclass' methods) into my Pager class.

Preserve the scroll position of a Page

I have a page with many elements (forms and tables)
When I want add a row in a table I scroll the page to the table, I press a button to add a row, edit the info in a popup and press OK.
Then I insert the new row in the model and refresh() the model.
At this point the page auto scroll at the top, but I don't want this behavior!
I want that the page stay in the same Y position!
I see that sap.m.page has scrollTo function https://openui5.hana.ondemand.com/docs/api/symbols/sap.m.Page.html#scrollTo
but I don't know how take the position before the refresh()
The Page does unfortunately not have an API to get the current scroll position, but the idea is a good one we consider.
As a workaround you could access some private method of the Page - but only if you accept the risk that it breaks with a future version of UI5:
page.getScrollDelegate().getScrollTop()
To make it safer you should verify both methods exist before calling them and also check the returned value for plausibility. Then you are pretty safe that in the worst case it will again scroll to the top in some future UI5 version.
you have to fill the iTime parameter in scrollTo function - e.g. srollTo(100, 1) - then it works
using 0 for iTime does not work

Pager starts to change pages back and forth when clicking page links fast

I have a Pager extended from AbstractPager in which every time on range or row count changed I recreate NavLinks contained in it so pager looks like this:
1 2 3 … N-1 N N+1 … M-2 M-1 M
My algorithm works fine but when I start clicking on links fast (like really furiously) by the time one RangeChange event is performing (CellTable to which my pager is attached shows spin trying to fetch data on given page) there's already another ones coming to the EventBus. It results in changing current page back and forth in an infinite loop.
I tried to make paging links enabled only when current page is competely fetched by using Scheduler.get().scheduleDeferred and .scheduleFinally but with no luck.
My temporary solution is to enable paging links after 500 ms by using Scheduler.get().scheduleFixedDelay(), but I want to know how to get the exact moment of data on the current page being fully fetched.
Thanks.
If you have the same problem you need to hang LoadingChangeEvent.Handler on your CellTable, check if data is fully loaded and inform pager about it so pager can activate it's NavLinks:
pager.setDisplay(cellTable);
cellTable.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() {
#Override
public void onLoadingStateChanged(LoadingStateChangeEvent event) {
if (event.getLoadingState() == LoadingStateChangeEvent.LoadingState.LOADED) {
pager.activateNavLinks();
};
}
});
There's no way to do it internally in your pager since setDisplay() accepts HasRows and addLoadingStateChangeHandler() is in AbstractHasData (AbstractHasData implements HasData, HasData implements HasRows).