Skip to Content
0

Filter not working

Mar 01 at 05:40 PM

184

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jun Wu Mar 01 at 06:22 PM
1

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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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

0

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

0

no, i just select 10 materials from mara

0
Emanuele Ricci Mar 02 at 09:48 AM
0

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?

Show 2 Share
10 |10000 characters needed characters left characters exceeded

the result of my odata service?

0

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).

0
Vaibhav Maheshwari Mar 02 at 02:02 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded