Skip to Content
0

How to make a filter with OData?

Nov 14, 2016 at 12:43 PM

173

avatar image
Former Member

Hello!

Could you help me and maybe tell how filters with OData working? Unfortunately, table filters don't work...Should I this problem in ABAP Backend decide? Or maybe do you see some code mistake? In Metadata file it's no any significance that my data are not filterable...

Group by is working

But ascending und descending dont't work....

In softwaretools there are informatoin that this request works...

Code example...

	return Controller.extend("Statusverwaltung3.controller.Table", {
		_oDialog: null,
		onInit: function() {


			var itemData = new Array();


			itemData.push({


				Key: "01",


				Text: "KS"


			});


			itemData.push({


				Key: "02",


				Text: "OR"


			});


			itemData.push({


				Key: "03",


				Text: "PC"


			});


			itemData.push({


				Key: "04",


				Text: "PR"


			});
			var oData = {
				Status: [{


					name: 'Offen',
					measure: '0',
					id: 1
				}, {
					name: 'In Bearbeitung',
					measure: '19',
					id: 2
				}, {
					name: 'Geplant',
					measure: '13',
					id: 3
				}, {
					name: 'Abgeschlossen',
					measure: '0',
					id: 4
				}, {
					name: 'Geprüft',
					measure: '0',
					id: 5
				}, {
					name: 'Freigegeben',
					measure: '0',
					id: 6
				}]


			};


			var model1 = new sap.ui.model.json.JSONModel();


			model1.setData(oData);


			var comboSelMdl = new sap.ui.model.json.JSONModel({


				SelKey: "01",


				Items: itemData


			});


			this.getView().setModel(comboSelMdl, "comboSelMdl");
			this.mGroupFunctions = {
				Obart: function(oContext) {
					var obart = oContext.getProperty("Obart");
					return {
						key: obart,
						text: obart
					};
				},


				Pjahr: function(oContext) {
					var pjahr = oContext.getProperty("Pjahr");


					return {
						key: pjahr,
						text: pjahr
					};


				},
				Kokrs: function(oContext) {
					var Kokrs = oContext.getProperty("Kokrs");


					if (Kokrs <= 1000) {
						var key = "LE100";
						var text = "1000 " + " or less";
					} else if (Kokrs <= 1000) {
						key = "BT100-1000";
						text = "Between 100 and 1000 ";
					} else {
						key = "GT1000";
						text = "More than 1000 ";
					}


					return {
						key: Kokrs,
						text: Kokrs
					};


				}
			};
		},


	


},


		handleViewSettingsDialogButtonPressed: function(oEvent) {
			if (!this._oDialog) {
				this._oDialog = sap.ui.xmlfragment("Statusverwaltung3.view.Dialog", this);
			}
			// toggle compact style
			jQuery.sap.syncStyleClass("sapUiSizeCompact", this.getView(), this._oDialog);
			this._oDialog.open();


		},


		handleConfirm: function(oEvent) {
				var oView = this.getView();
				var oTable = oView.byId("idStats");


				var mParams = oEvent.getParameters();
				var oBinding = oTable.getBinding("items");


				// apply sorter to binding
				// (grouping comes before sorting)
				var aSorters = [];


				if (mParams.groupItem) {
					var sPath = mParams.groupItem.getKey();
					var bDescending = mParams.groupDescending;
					var vGroup = this.mGroupFunctions[sPath];
					aSorters.push(new sap.ui.model.Sorter(sPath, bDescending, vGroup));
				}
				var sPath = mParams.sortItem.getKey();
				var bDescending = mParams.sortDescending;
				aSorters.push(new sap.ui.model.Sorter(sPath, bDescending));
				oBinding.sort(aSorters);
			}
			/**
			 * Called when a controller is instantiated and its 
	onChange: function(oEvent) {
			// getting the value of Combobox
			var oTable = this.getView().byId("idStats");
			oTable.setShowOverlay(true);
		},


		onSearch: function(oEvent) {
			var oTable = this.getView().byId("idStats");
			var comboBoxValue = this.byId("oComboBox").getValue(),
				oBinding = oTable.getBinding("items"),
				oFilter;
			if (comboBoxValue || comboBoxValue === "") {
				oTable.setShowOverlay(false);
				oFilter = new sap.ui.model.Filter("Obart", "EQ", comboBoxValue);
				oBinding.filter([oFilter]);


				// getting the value of Combobox


			}
			oTable.setShowOverlay(true);


		},
		onReset: function(oEvent) {
			// resetting the value of Combobox and initial state of the table
			var oTable = this.getView().byId("idStats");
			var oBinding = oTable.getBinding("items");
			oBinding.filter([]);
			oTable.setShowOverlay(false);
			this.byId("oComboBox").setSelectedItem(null);
		},


So, there are some mistakes or I should make filteres firstly in SAP system?....I have no idea...Combobox doesn't work too...

Thank you in advance !

Regards,

Khristina

takl.png (51.6 kB)
ta.png (59.1 kB)
ta4kl.png (119.9 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Simon Perstorfer Nov 16, 2016 at 12:16 PM
0

Hi Khristina,

filters are done in the backend. If you are using Gateway, please follow the link below for more informations.

https://blogs.sap.com/2013/06/20/how-to-develop-query-options-for-an-odata-service-using-code-based-implementation

Do you have implemented the backend side for filters?

Regards

Simon

Share
10 |10000 characters needed characters left characters exceeded