Florian
Florian

Reputation: 5061

How do I force the SmartTable to load all items?

My SAP UI5 view contains a SmartTable that is bound to an entity set in an ODataModel in read-only mode.

The table limits the number of items it displays to 100, verifiable by the ?$top=0&$limit=100 parameters it appends ot the data query to the server.

However, my users would like to have the table load and display all items, without paging or having to press some "More" button.

Is there a way to override the SmartTable's default behavior? For example by setting some growingSize property to "Infinity"? Or by modifying the aggregation binding? Or by adding annotations to the OData service?

Upvotes: 3

Views: 9363

Answers (2)

Roman
Roman

Reputation: 61

You can achieve this by using a formatter function which will return how many entries are within your model.

<SmartTable growingThreshold = "{path:'yourModel>/', formatter:'.formatter.sizeCalculator'}">

In the formatter File, which is usually to find in the model folder:

sizeCalcualtor: function(oModel){
  let count = 0;
  for(let i in oModel){
    //add item to count;
  }
return count;
}

Upvotes: 0

Jorg
Jorg

Reputation: 7250

Since you did not specify the number of expected items or the table you're using here are some general considerations and a few possible solutions.

The type of table

There are a few things to consider between the varying types of tables you can use, there is some advice of SAP itself from the design guidelines:

Do not use the responsive table if: You expect the table to contain more than around 1,000 rows. Try using the analytical table or grid table instead; they are easier to handle, perform better, and are optimised for handling large numbers of items.

Ways around it

First option I can think of, if you're using a responsive table and you expect less than 1000 rows then the scroll to load feature might be of interest which should load more entries when the user reaches the bottom of the current list.

There are ways to increase the default size of 100, both through the table using the growingThreshold property, or through the declaration of the oData model using the sizeLimit

If you're using a grid table then the scroll-to-load works slightly differently, since it doesn't display all rows at the same time. Instead, it destroys the current lines to display new lines, which is why it's recommended for (very) large datasets.

Second, if none of those solutions work for your users you could alternatively first fetch the count of the current list including filters, so you can set an accurate threshold on the table before displaying results. If done correctly, your oData service should return a count using /myserivce/MyEntity/$count?$filters... when queried. CDS does this automatically, older services will need to implement that separately.

Last, if you know the list never exceeds a certain number of lines, you could set the growingThreshold parameter on the table to that number and then you don't have to worry about fetching an accurate count first.

How all of this is implemented depends a bit on how you create the smart table (elements, manually etc) so I'm not sure how to provide usable example code

Upvotes: 3

Related Questions