cancel
Showing results for 
Search instead for 
Did you mean: 

How to Bind Filtered Data to List

Former Member
0 Kudos

Hi Experts,

I am using a list control for master detail template and successfully binded Entityset fields to display in list.

Now how can use filter query and bind it to list control.

/sap/opu/odata/SAP/MYNEWSERVICE_SRV_02/SalesDetailSet?$filter= Soldtoparty eq '100'

the filter query results with multiple values which are to be binded. to List control. Currently SalesDetailSet all values are binded to list.

Are there any sample code to use as reference, please suggest.

Thanks in advance

Kumar

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor

here u go

Using Extended Syntax to Add Filters and Sorters - UI Development Toolkit for HTML5 (SAPUI5) - SAP L...

<table:Table rows="{

  path: '/table',

  filters: [{

  path: 'field3',

  operator: 'EQ',

  value1: 'test'

  }],

  sorter: [{

  path: 'field1',

  descending: false

  }, {

  path: 'field2',

  descending: true

  }]

}">

...

</table:Table>

Former Member
0 Kudos

Hello Jun ,

I am using a List control , to bind the filtered data to list. can you suggest some thing similar to filter with List control?

Former Member
0 Kudos

Hi Kumar,

Jun just told you how we can use filters in binding. You can use the same logic for list control too. Just when you mention path in the binding attribute (items) you need to add the filters like Jun has mention in his answer.

thanks

Viplove

Former Member
0 Kudos

How do i pass it dynamically instead of hardcoding?

path: 'field3',

  operator: 'EQ',

  value1: 'test'

the 'test' value comes from a dialog.fragment.xml list ? the fragment code is as below.


<core:FragmentDefinition

  xmlns="sap.m"

  xmlns:core="sap.ui.core">

  <SelectDialog

  noDataText="No Data Found"

  title="Select Sales Org"

  search="handleSearch"

  confirm="handleClose"

  cancel="handleClose"

  items="{

  path: '/F4_SalesOrganizationSet'

  }"

  >

  <StandardListItem

  title="{Vkorg}"

  description="{Vtext}"

  type="Active" />

  </SelectDialog>

</core:FragmentDefinition>

handle close function of fragment


handleClose: function(oEvent) {

var aContexts = oEvent.getParameter("selectedContexts");

if (aContexts.length)

{ sap.m.MessageToast.show("You have chosen Sales Organization" + aContexts.map(function(oContext) { return oContext.getObject().Vkorg; }).join(", "));

});

List Code in Master Page

Currently the filter is hardcoded , but the value is to be collected from the fragment list and filtered upon the list and binded in master page.


filters: [{ path: 'Salesorganization', operator: 'EQ', value1: '2000' }], 


<List

id="list"

items="{ path: '/CustomersListSet',

filters: [{ path: 'Salesorganization', operator: 'EQ', value1: '002' }],

sorter: { path: 'Soldtoparty', descending: false },

groupHeaderFactory: '.createGroupHeader' }"

busyIndicatorDelay="{masterView>/delay}"

noDataText="{masterView>/noDataText}"

mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}"

growing="true" growingScrollToLoad="true"

updateFinished="onUpdateFinished"

selectionChange="onSelectionChange">

<infoToolbar>

<Toolbar active="true" id="filterBar" visible="{masterView>/isFilterBarVisible}" press="onOpenViewSettings">

<Title id="filterBarLabel" text="{masterView>/filterBarLabel}"/>

</Toolbar> </infoToolbar>

<items>

<ObjectListItem type="{= ${device>/system/phone} ? 'Active' : 'Inactive'}" p

ress="onSelectionChange" title=" {Customername} ({Soldtoparty})">

<firstStatus>

<ObjectStatus text="Salesorganization: {Salesorganization}"/> </firstStatus>

<attributes></attributes> </ObjectListItem> </items>

</List>

Former Member
0 Kudos

Hi Kumar,

It is not possible to give dynamic values to filter in XML.

Instead do binditems in controller  along with filter having dynamic values

former_member185414
Active Contributor
0 Kudos

As suggested by others and noted here at github it is not possible right now to have dynamic filtering in XML views.

As also suggested try pass the filters during binding in controller file.

BR.

Former Member
0 Kudos

Ankit, Jagadessh,

Can you please suggest any code snippet for this.

I came across a similar requirement in a thread Dynamic OData filter in sap.m.List (XML View) | SCN but trying to allign with my requirement .

Sai Vellanki's Profile | SCN

Please suggest via a code snippet

Former Member
0 Kudos

Hi Kumar,

I think the link u provided contains the solution snippet ur looking for,in place of

navigator.language.substr(0,1).toUpperCase() pass ur values dynamically. try with following code

                              var oCustomerCountry =this.getView().byId("list");

                            

                              var oSorter= {

                                                path: 'Soldtoparty',

                                                descending: false,

                                                group: true

                                              };

                            

                                          var oFilters = new sap.ui.model.Filter("Salesorganization", sap.ui.model.FilterOperator.EQ,                                                                                                     navigator.language.substr(0,1).toUpperCase());  // Dynamic parameter

                               oCustomerCountry.bindItems("/CustomersListSet", oSorter, oFilters);

Former Member
0 Kudos

Can you please modify the snippet as per my view code. I am trying to use the one from the link, but could nt.

Sai Vellanki

Any suggestions please

former_member185414
Active Contributor
0 Kudos

Dynamic filtering in XML or declarative views is not possible. Please correct me if wrong.

saivellanki
Active Contributor
0 Kudos

Hi Kumar,

You mean something like this? Plunker

Regards,

Sai.