Skip to Content
0

select sort sapui5

Mar 20, 2017 at 02:00 PM

49

avatar image
Former Member

Hi experts,

I need to make a sort from WorkCenterID. I already try a lot of ways, but I don´t have a good result.

configureSelectBox: function () {
		var i=0;
        var params = this.getPageParamsFromInputModel();
        var select = this.getView().byId("workCenterSelect");
        var oInputModel = this.getView().getModel("input");
        var workCenterName=[];
        
        oInputModel.setProperty("/WorkCenterID", params.workCenterID);
        var oProductionModel = this.getModel(this.constants.MODELS.PRODUCTION);
        console.log(oProductionModel.oData);
	        for (u in oProductionModel.oData){
	        	if (typeof oProductionModel.oData[u].WorkCenterName != "undefined") {
		        	if (oProductionModel.oData[u].WorkCenterName !=""){
		        		workCenterName[i]=[oProductionModel.oData[u].WorkCenterID, oProductionModel.oData[u].WorkCenterName, oProductionModel.oData[u].Description];
		        		i++;
		        	}
	        	}
        }
	    if (workCenterName!=""){    
	    	localStorage.setItem('workCenterName', JSON.stringify(workCenterName));
	    }
        select.setModel(oProductionModel);
        select.bindItems({
            path: '/CellSet',
            template: new sap.ui.core.Item({
                key: '{WorkCenterID}',
                text: '{Description}'
            }),
            sorter:  [new sap.ui.model.Sorter("WorkCenterID",false,false, function (a, b) {
            	
                if (parseInt(a.WorkCenterID) > parseInt(b.WorkCenterID)) {
                    return 1;
                    console.log(a.WorkCenterID);
                }
                else if (parseInt(a.WorkCenterID) < parseInt(b.WorkCenterID))
                {
                    console.log(b.WorkCenterID);
                	return -1;
                }


                return 0;
            })],
            filters: [new sap.ui.model.Filter([
                new sap.ui.model.Filter('LanguageID', sap.ui.model.FilterOperator.EQ, params.languageID),
                new sap.ui.model.Filter('WorkCenterID', sap.ui.model.FilterOperator.NE, '00000000'),
                new sap.ui.model.Filter('LayoutID', sap.ui.model.FilterOperator.EQ, params.layoutID)
            ], true)]
        });
    },

Someone can help me!

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

2 Answers

Best Answer
Jun Wu Mar 20, 2017 at 03:13 PM
0

what's the version of your odata model? usually sort happens at server side for old odata model.

Share
10 |10000 characters needed characters left characters exceeded
Ivan Mirisola
Dec 20, 2017 at 01:43 PM
0

Hi André,

Use the orderby attribute for the odata protocol from here:

http://services.odata.org/OData/OData.svc/Products?$orderby=Rating

This will bring data from this service for all Product Entries returned in ascending order when sorted by the Rating Property.

Regards,
Ivan

Share
10 |10000 characters needed characters left characters exceeded