cancel
Showing results for 
Search instead for 
Did you mean: 

I'm getting getBinding undefined. I have used it twice in init function and onSort function

rhia23
Discoverer
0 Kudos
onInit: function () {
             var otable= this.getView().byId("Table1");
 var oModel = new sap.ui.model.json.JSONModel();
 oModel.loadData("model/data.json");
  var oModel1= this.getView().setModel(oModel);  

 //Initial sorting 
 var sPath, bdesc, aSorters=[] ;
 sPath ="EmpNo";
 bdesc = false;
 aSorters.push(new Sorter(sPath, bdesc));
 this.byId("Table1").getBinding("rows").sort(aSorters);
         },

 onSort : function(oEvent) {

   var mParams = oEvent.getParameters(),
sPath,
bDescending,
aSorters = [];
//sPath = mParams.sortItem.getKey();
   sPath="EmpName";
// bDescending = mParams.sortDescending;
  bDescending = false ;
aSorters.push(new Sorter(sPath, bDescending));
var oList = this.byId("Table1");
this.oList.getBinding("rows").sort(aSorters); }
rhia23
Discoverer
0 Kudos

I have used a sap.ui table in which initially i want to sort it to by EmpNo and when i click on sort button, then it should sort by EmpName. I have used json data in this .

Now in the code, I did sorting in onInit fn and onSort fn but only one is working at a time. In the code, i'm getting error in onSort fn that :- Uncaught TypeError: Cannot read property 'getBinding' of undefined

View Entire Topic
former_member508209
Participant
0 Kudos

Hi rhia23,

Welcome to the community!

The provided information is still a bit little, I will give it a try anyway. It looks like you are having two different errors here:

1. The `onInit` is executed before the data bindings are available. Therefore, the error should be something similar to "Uncaught TypeError: Cannot read property 'sort' of undefined". If you have to work with the bindings, you can put your coding into the `onBeforeRendering` handler. Alternatively, as you are not using any dynamic conditions for sorting, you can directly define it in the binding in your xml file: `{ path: '<your path>', sorter: { path: '<your sorting path>', descending: false }}`

2. In your `onSort` method, you are calling `getBinding` on a property `this.oList`, whereas your intended table is stored as `var oList`. Therefore I guess you have an "Uncaught TypeError: Cannot read property 'getBinding' of undefined". You can fix this by calling `getBinding` on the right object.

In general, with only a very short description in the title, it is hard to tell what your actual error could be. It would be much easier for people to help you, if you provided a more detailed description, describing what you have tried, what the expected result would be and what the error was. Additionally, some screenshots come in handy to illustrate the actual behavior.

Please let me now if my hints already helped you by accepting the answer or providing further information to analyze your issue.

Best,

Janik