cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with filter

rhightower13
Participant
0 Kudos

I have a list of employees that I'm trying to filter based on a department id.  I've used the following statement in the createContent function to create the filter:


var oFilter1 = new sap.ui.model.Filter("department", sap.ui.model.FilterOperator.EQ, "100");

The app runs fine without this line except that it doesn't filter the employee list.  However, when I insert this statement the app displays nothing and in Chrome I get the following error on the filter statement:

Uncaught TypeError: Cannot read property 'EQ' of undefined.

Any ideas would be greatly appreciated.

Thanks,

Ross

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

I do not see anything wrong with it. The error message just means that it was not able to load the library required for operator 'EQ'.

I would try once with below statement,

oFilter1 = new sap.ui.model.Filter("department", "EQ", "100");

rhightower13
Participant
0 Kudos

That did it.  Don't think I've seen that syntax anywhere.

Than you,

Ross

Answers (1)

Answers (1)

SandipAgarwalla
Active Contributor
0 Kudos

how are you setting the model for the filter?

rhightower13
Participant
0 Kudos

I am trying to filter the list like this but that's obviously not right because it isn't working:

var oFilter1 = new sap.ui.model.Filter("department", "EQ", 100);

   var employeeList = new sap.m.List({

  inset : true,

  type : sap.m.ListType.DetailAndActive,

  headerText : "Employee List",

  filters : [oFilter1]

  });

SandipAgarwalla
Active Contributor
0 Kudos

try to Add, jQuery.sap.require("sap.ui.model.FilterOperator"), either just before the filter decl or index html

rhightower13
Participant
0 Kudos

That worked but the filter isn't working where I put it.

Thanks,

Ross

SandipAgarwalla
Active Contributor
0 Kudos

I would try this once


var filters = [] ;


filters.push(new sap.ui.model.Filter("department", "EQ", 100));


var employeeList = new sap.m.List({

  inset : true,

  type : sap.m.ListType.DetailAndActive,

  headerText : "Employee List",

  filters : filters

  });

rhightower13
Participant
0 Kudos

I've tried just about every combination I can think of and the filter just doesn't work.  Not sure what to do at this point.  I created a small test version of my data to experiment and I've pasted the relevant portions of my code below in hopes that someone can see something in it.  In Chrome, can see that the list includes the filter but, for some reason it is not being applied.

If anyone has any suggestions I would greatly appreciate it.

Ross

var dataObjectEmp = {

  data : [ {

  index : 0,

  name : "Bob Small",

  department : 100

  }, {

  index : 1,

  name : "Sally Small",

  department : 100

  }, {

  index : 2,

  name : "John Small",

  department : 200

  }, {

  index : 3,

  name : "Alice Small",

  department : 200

  }, ]

  };

 

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

  eModel.setData(dataObjectEmp);

  sap.ui.getCore().setModel(eModel, "emp");

...

var filters=[];

  jQuery.sap.require("sap.ui.model.FilterOperator");

  var oFilter1 = new sap.ui.model.Filter("department", sap.ui.model.FilterOperator.EQ, 100);

  filters.push(oFilter1);

   var employeeList = new sap.m.List({

  inset : true,

  type : sap.m.ListType.DetailAndActive,

  headerText : "Employee List",

  filters : filters

  });

var oItemTemplateHtml = new sap.m.StandardListItem({

  title : "{emp>name}",

  description: "{emp>department}",

  iconInset: false,

  type:'Active'

  });

employeeList.bindItems('emp>/data',oItemTemplateHtml);