Skip to Content

Filter not working

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Mar 01 at 06:22 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 02 at 09:48 AM

    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?

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 02 at 02:02 PM

    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

    Add comment
    10|10000 characters needed characters exceeded