cancel
Showing results for 
Search instead for 
Did you mean: 

sap.m.Table with Growing - Load All Data?

shais
Participant
0 Kudos

Hi,

I'm using sap.m.Table (with binding to JSON model) with growing enabled.

I would like to add a new button "Load All" which will load all the data (once), despite the standard growing behavior.

Is there any way to load all data at once when growing is set (even by temporarily disabling growing)?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Shai,

very interesting question! I haven't implemented such fuctionality before, but did some experience today and it works.

In the View, you first define a Button:

<Button text="Fetch All" press="onFetchAll"/>

then, implement the Press Event in the controller:

onFetchAll: function(oEvent) {
  var oTable = this.getView().byId("idTable"); //replace the id of your table
  oTable.setGrowingThreshold(oTable.getMaxItemsCount()); //set threshold the max
  oTable.getBinding("items").filter(); //refresh the table
},

The filter() / sort() method is used to refresh the table. Perhaps, there is a better way to do it.

I hope it could help you.

shais
Participant
0 Kudos
Thanks.

Interesting solution.
It does seem to work.

Using filter/sort to refresh the table is a nice trick.
P.S. For some reason, setGrowing(false) doesn't work as expected (like setGrowingThreshold).

former_member651202
Discoverer
0 Kudos

Hi Haolin Zhi,

It works fine when need all the binding items from the table.

But it will not work, if the sap.m.Table has filter option. In that case, it always loads all the 'N' records from the model.

Scenario:

I have sap.m.Table with 500 records and filter is applied. Need to download the filtered data from the table.

onFetchAll: function(oEvent) {
  var oTable = this.getView().byId("idTable"); //replace the id of your table
  var nGrowingThreshold = oTable.getGrowingInfo().total; //total model threshold is 500
  oTable.setGrowingThreshold(nGrowingThreshold); //set default threshold from 100 to 500
  oTable.getBinding("items").filter(); //refresh the table
  
  var aItems = oTable.getItems(); //always returns all 500 records
},

The above code refresh the table with all the model data and downloads all the 500 records instead of downloading only the filtered records. I am facing such an issue.

Please help me on this issue.

Regards,

Umesh

Answers (1)

Answers (1)

former_member651202
Discoverer
0 Kudos

The below code solved my issue.

onFetchAll:function(oEvent){
  var oTable = this.getView().byId("idTable"); //replace the id of your table
  var nTableThreshold = oTable.getGrowingInfo().total;
  oTable.setGrowingThreshold(nTableThreshold);
  oTable.getBinding("items").sort(); //refresh the table
  
  var aItems = oTable.getItems(); // returns only the filtered records
},
shais
Participant
0 Kudos

As haolin-zhi has already mentioned, both filter and sort function refresh the table.

In case you don't want to affect existing sorting/filter, you'll have to set pass parameter of sort/filter.