cancel
Showing results for 
Search instead for 
Did you mean: 

Filter not working

03-01-2018 6:40 PM
naotoxxx Participant
2513 views 8 comments
0 Likes
SAP Managed Tags
Subscribe

Hi i'm triying to filter my list but is not working, i tried with search fild, input an submit and not success this is my view:

	<App>
		<Page title="{i18n>titulo}">
			<content>
			<SplitContainer id="SplitContDemo" initialDetail="detail" initialMaster="master">
				<detailPages>
					<Page id="detail" title="Resultados" class="sapUiStdPage">
						<content>
						<SearchField width="auto" search="onSearch" class="sapUiTinyMargin" />
							<List  	   id="lista"
									   items="{ path: '/MaterialListSet',
												sorter: {
					      	  						path: 'MTYPE',
					      	  						descending: false,
					      	  						group: true
					      	  					}
									   }"
									   growing="true">
							<items>
									<ObjectListItem title="{MATERIAL}"
													type="Active"
													press=""
													number= "{MTYPE}"
													icon="sap-icon://database">
										<firstStatus>
											<ObjectStatus 	title="{ULT_MODIF}"/>
										</firstStatus>
										<secondStatus>
													<ObjectStatus
														title="{i18n>GrupoArt}"
														text="{GP_ART}"/>
										</secondStatus>
										<attributes>
											<ObjectAttribute text="{RESPONSABLE}" />
											<ObjectAttribute text="{SIZE}" />
										</attributes>
									</ObjectListItem>
								</items>
							</List>
						</content>
					</Page>
				</detailPages>
				
				<!-- Resultado -->
				<masterPages>
					<Page id="master" title="Buscar" icon="sap-icon://action" class="sapUiStdPage">
						<content>
					      		
					      		<Label text="Categoría" />
										<Input id="cat" value="" tooltip="Ejemplo: 11111 , 22222 , A4333" submit="onSearchs"/>
										<Toolbar>
										<ToolbarSpacer/>
											<Button icon="sap-icon://search" type="Default" press="onSearch"/>
										</Toolbar>
								
						</content>
					</Page>
				</masterPages>
			</SplitContainer>
				
			</content>
		</Page>	
	</App>

and this is my controller, check i have a fuction for each element, input, search field an submit

		onSearch : function(oEvt) {
			// build filter array
			var aFilter = [];
			// fetch event parameter
			var sQuery =  oEvt.getSource().getValue();
			
			if(sQuery && sQuery.length > 0) {
				var filter = new Filter("RESPONSABLE", sap.ui.model.FilterOperator.Contains, sQuery);
				aFilter.push(filter);
			}
			
			var list = this.getView().byId("lista");
			var binding = list.getBinding("items");
			binding.filter(aFilter, "Application");
		},
		onSearchs : function(oEvent) {
			// build filter array
			var aFilter = [];
			// fetch event parameter
			var sQuery = oEvent.getParameter("value");
			// Regresa la lista
			var oList = this.getView().byId("lista");
			// get binding for aggregation 'items'
			var oBinding = oList.getBinding("items");


			if (sQuery) {
				aFilter.push(new Filter("RESPONSABLE", FilterOperator.Contains, sQuery));
			}
			// apply filter. an empty filter array will show all items
			oBinding.filter(aFilter);
		},
		
		onSearch : function(oEvent) {
			// build filter array
			var aFilter = [];
			// fetch event parameter
			var sQuery = this.byId('cat').getValue();
			// Regresa la lista
			var oList = this.getView().byId("lista");
			// get binding for aggregation 'items'
			var oBinding = oList.getBinding("items");


			if (sQuery) {
				aFilter.push(new Filter("RESPONSABLE", FilterOperator.Contains, sQuery));
			}
			// apply filter. an empty filter array will show all items
			oBinding.filter(aFilter);
		}

"RESPONSABLE" it's the property of my entity of the odata , yes, in capital so, can you see something that i'm not ? and also i don't get any error

0 Likes

Accepted Solutions (0)

Answers (3)

Answers (3)

junwu
SAP Champion
SAP Champion

if you bind to odata directly, the filtering has to be implemented in your odata code. check with your odata developer if he has done the job or not.

naotoxxx
Participant
0 Likes

i'm the odata developer, fiori anba little basis jejeje but i'll check be cause i don't know if i check those optiones to filter

junwu
SAP Champion
SAP Champion
0 Likes

then you should be very clear, have you done anything in your code to do the filtering?

naotoxxx
Participant
0 Likes

no, i just select 10 materials from mara

mvaibhav
Contributor
0 Likes

HI Naoto,

Is your service method reading the filter parameters passed to it and returning the correct data(filtered data) ?

Your backend service method should read the filters passed and return the filtered data to UI5.

Thanks,

Vaibhav Maheshwari

Former Member
0 Likes

First of all, you should use SearchFiled (for UI and UX reasons) instead of the Input.

SearchField supports two events:

  • search -> the query value is inside the query parameter
  • liveChange -> the query value is inside the newValue parameter

after that event you can filter your binding. Your code seems fine, can you show us the query result or can you create a jsbin?

naotoxxx
Participant
0 Likes

the result of my odata service?

Former Member
0 Likes

If you open the chrome developer tool you can see the network call. I need to know the query parameter (if you filter function is applying Filter correctly).