cancel
Showing results for 
Search instead for 
Did you mean: 

select sort sapui5

Former Member
0 Kudos

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!

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

0 Kudos

Hi

Try using odata call. Enhance your oData method for sorting then you can easily sort.

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos

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