Skip to Content
-1

How to filter using odata.read and bind to Smart table.

Aug 23, 2017 at 11:37 AM

443

avatar image
Former Member

Hello Experts,

I have a smart table tableType= Table entitySet="POHeaderSet",

a grid table is automatically created named 'headertable-ui5table'

i am getting metadata as follows

var sUrl = "/sap/opu/odata/SAP/ZBMEGW_E1483_MASSCHANGEPO_SRV/";

var oModel = new sap.ui.model.odata.ODataModel(sUrl, true);

now what i want is, filter the data coming from back end. That i am doing as below

var oModel = new sap.ui.model.odata.ODataModel(sUrl, true);

oModel.read(filter, null, null, true, function(oData, response) {

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

dropModel.setData(oData.results); that.byId("headertable-ui5table").setModel(dropModel);});

when i do the above it says no data, if i directly set the oModel to the view i am getting all the data from backend.

In back end get_entity_set i have below:

i am getting the filter in lt_ebeln if passed through oModel.read();

Select*from ekko into table where ebeln in lt_ebeln

How do i filter the data from the entity set and then set the model to the smart table as smart table is not accepting JSON ?

Can i use the smart table container and create normal sap.ui.table.Table inside the smart table container and then set the json model to that table ? if so then will it behave same as exposing smarttable to metadata ?

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

2 Answers

Best Answer
avatar image
Former Member Jan 11 at 07:06 AM
0

Hi irfan,

Thanks for the response but the above procedure cannot be used in smart tables.

we have to pass our filters values to the bindingparams filter property of the smart table in before rebind table method in controller. In that way the smart table will fetch the filtered values

Share
10 |10000 characters needed characters left characters exceeded
Irfan Gokak Aug 24, 2017 at 09:32 AM
0

Hope below code will help for filtering data.

var oFilters = [],
	oModel = this.getView().getModel(),
oFilters.push(new Filter("ImType",FilterOperator.EQ,"RE"));
oFilters.push(new Filter("ImPernr",FilterOperator.EQ,Eno));
oModel.read("/EmpListSet", {
	filters: oFilters, 
	success : function(oData, oResponse){
		//execute in case of call success
                //your binding goes here
	},
	error : function(oData, oResponse){
		//execute in case of call fail
		var obj = JSON.parse(oData.response.body);
		var msg = obj.error.message.value;
		sap.m.MessageBox.show(msg, {
			icon: sap.m.MessageBox.Icon.ERROR,
			title: "Error",
			actions: [sap.m.MessageBox.Action.OK]
		});
	}
});
Share
10 |10000 characters needed characters left characters exceeded