on 05-17-2021 9:56 AM
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); }
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.