Vaadin Flow Grid. How get the data/rows from grid - vaadin10

i use Grid with DataProvider and lazy loading to load the data into the grid.
How can i get the data from grid after the data was loaded? I mean, i need get a data from grid that already have a data.
i need something like grid.get....
thx.

I would use grid.getDataCommunicator().fetchFromProvider(..) which returns stream of items method for this, see API spec here: https://demo.vaadin.com/javadoc/com.vaadin/vaadin-core/10.0.2/com/vaadin/flow/data/provider/DataCommunicator.html#fetchFromProvider-int-int-

Since Vaadin 17, you can use DataView API to get currently shown item/items in the Grid:
GridDataView<Person> dataView = grid.getGenericDataView();
Person item = dataView.getItem(42);
// or get all shown items
dataView.getItems().forEach(item -> export(item));
Here is an example how to collect the data for export: https://vaadin.com/docs/latest/flow/binding-data/data-provider/#accessing-currently-shown-items

Related

Vaadin Grid - Attempted to fetch more items from server than allowed in one go

~1500 data need to be fetched from DB. The code is pretty simple
List<Item> itemList = getItemsFromDB();
Grid<Item> grid = new Grid<>();
grid.addColumn(Item::getID).setHeader("Id").setAutoWidth(true);
grid.addColumn(Item::getName).setHeader("Name").setAutoWidth(true);
grid.setAllRowsVisible(true);
grid.setItems(itemList);
And I got this warning, only the first 1000 data are shown in the grid, the rest are just empty rows.
2022-04-15 15:46:52.475 WARN 19642 --- [nio-8080-exec-6] c.v.flow.data.provider.DataCommunicator : Attempted to fetch more items from server than allowed in one go: number of items requested '1583', maximum items allowed '1000'.
I know I can use lazy loading, but can I do it without it? The size of data will always be around 1500, and I don't actually care that much about how slow it is.
I am using vaadin 14.8.8
The problem comes from setAllRowsVisible and the DoS protection added inside the data provider. It's currently not easily possible to overwrite this without creating your own data provider.
I'm not really sure why you need all the rows visible; this increases the load time for your end user. If your only reason is to have the grid full height, you can just call setHeight on the grid and the let Vaadin handle the callbacks to the server to only fetch the amount of data needed to show on the client.

Angular 11 Material DataSource without further Requests to the Server

I've been playing around with the example table-schematic for the Material Design [version: 11.0.3] table.
Basically i want to make a request, take the response and display it with the options to sort and limit the displayed items (pagination).
It works fine if I just replace the content of the connect function with "return a mapped Observable of the Response" but then the sorting and pagination obviously don't work anymore (since they are deleted) and i can't figure out how to make them work.
I assume the example pagination and sorting requires the data to be already present when the page loads/initializes (e.g. with a static Array).
Putting the request in the connect() function, saving the objects of the response to a variable and subscribing does work. However the page does not update after filling the initially empty array with data until sorting or pagination settings change. Which would make sense to me.
My question is, how do i get the data in there once and use the same data for pagination and sorting.
Can I even use the schematic in this case or is it misleading?
You can initialize a MatTableDataSource using an array of data, and then it will handle paging, filtering, and sorting locally and not try to fetch any more data.
See this example: https://stackblitz.com/angular/nleleddqmel?file=src%2Fapp%2Ftable-overview-example.ts
This example creates the data array locally, but you would instead use the response from your server request.

How to fetch row selection in Smart Table in List Report SAP Fiori app?

I am using the List Report template to implement an SAP Fiori app. The type of table is sap.ui.table.Table
I have added an extension for action to add a 'Download' button and I have set it's requiresSelection value to true. But I am not able to fetch the table selection.
I receive error
"Unsupported operation: sap.ui.table.Table#getSelectedIndices must not
be called if a selection plugin is applied."
for the below statement:
var oTable = oEvent.getSource().getParent().getParent().getTable();
//which fetches the table inside Smart Table control
oTable.getSelectedIndices();
Please help.
Try this:
Inorder to get the selected indices for the above error you are getting
var oTable = oEvent.getSource().getParent().getParent().getTable();
oTable.getAggregations("plugins")[0].getSelectedIndices();

Filtering Smarttables initial read request

im using a sap Smarttable to display my data from an ABAP Backend server. Additionally im using SmartVariantManagement to apply Variants and make them persistent.
The problem in my Application is the initial Load of the Smarttable. It seems like the table is first loading all the available data without any filters from the inital Variant of my Smartvariantmanagement.
Is there any way to apply the filters of Smartvariantmanagement to the initial Load in the Smarttable?
Or even better: Is it possible to shut down a running odata-read request if i apply a new selection in the smartfilterbar and just run the new one instead?
example 1:
you can avoid the initial request by the smarttable property
enableAutoBinding="false"
you can also set some mandatory fields for filtering, now the user performces an explicit call to the database
example 2:
you can also define a filter in the smarttable function
beforeRebindTable="onBeforeRebindTable"
controller:
onBeforeRebindTable: function (oEvent) {
var oBindingParams = oEvent.getParameter("bindingParams");
oBindingParams.filters.push(new sap.ui.model.Filter("PropertyX", "EQ", "myProperty"));
}
regards

How to get the last inserted row via Odata service

Update:
Using ODATA, How to get the last inserted row in /MySet where MySet.Name = "abc".
I do not want to continuously poll the odata service via model.read(). I know attachChange() or attachDataReceived()methods can be use to get notified automaically. But apart from notification, how to get the 'inserted row'. Also My doubt is how to satisfy the following three conditions here : $top=1, $orderby= Date desc and $filter=NAME eq 'ABC'
The only solution I can think of is to get notified by data inserted via attachDataReceived() and then make a model.read() call with the required filters and additional parameters. Although this would result in these additional 'read' calls.
Original Post Below:
Question: How to pass filters in element binding?
Post: I am using odata service for populating my views.
I want to pass certain filters like $filter=NAME eq 'Scott'
Since I want these parameters to be included only when with odata request for a specific ui-element, I want to include them in bindElement()
specifically something like this
var myFilter = new Array();
myFilter.push(new sap.ui.model.Filter("NAME", sap.ui.model.FilterOperator.EQ, 'Scott'));
var myStandardTile = this.byId("__tile3");
myStandardTile .bindElement("/MySet",{filters:myFilter});
But unfortunately this does not works. When I see the 'network' tab in developer console, Filters are not being added with my request.
You cannot. Neither filter nor sorter nor formatter are supported by element bindings. They are only supported by list and tree bindings.

Resources