javascriptsapui5

Get filtered data only from SapUi 5 Table


I have an application using a table of type sap.ui.table.Table. The table is setup using data binding using a local sap.ui.model.json.JSONModel and calling setModel() on the table itself. Sorting and filtering is also enabled so the user can easily show the data he needs. So far this works great.

My issue now is, is there a way to get the data based on the ordering and filter the user applied to the table? I would like to create a sum of values based on the current view.

I tried to call getRows() on the table, but it only returns the visible rows on screen. If there are more, those values are not returned. Other than that I don't find a matching method on table or the model that could return that data.

So is there a way to get that data or do I have to read the filter values and filter the data myself manually?


Solution

  • With getContexts() you get a reference to all data that is displayed in the list. You can get all data via

    list.getBinding("items").getContexts().map( c => c.getObject())
    

    Or the "dataset pointer"

    list.getBinding("items").getContexts().map( c => c.getPath())