Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2638

How to sort numbers in SAPUI5?

$
0
0

Hi all,

 

I tried to sort custom list items in my Employee list app based on Employee Number, Name and Designation.

The list gets sorted correctly when I sort it by name and Designation. But it's not getting sorted properly when I sort  it by Employee number. I mean the employee number is not taken as single number. Instead, it's taken as character by character.So even if the number is small, it gets sorted at the last.

Can someone help me with this?

 

Here’s what I have tried:

 

View coding:

 

var radiobtn1=new sap.m.RadioButton("radiobtn1",{enabled:true,selected:false,text:"Firstname",select:function(){globalradio="FirstName"; }});

 

var radiobtn2=new sap.m.RadioButton("radiobtn2",{enabled:true,selected:false,text:"EmployeeId",select:function(){globalradio="EmployeeId";}});


var radiobtn3=new sap.m.RadioButton("radiobtn3",{enabled:true,selected:false,text:"Designation",select:function(){globalradio="Designation";}});

 

var sortbtn=new sap.m.Image("sortbtn",{src:"jpg pics/sort4.png",press:function(){

 

  if(globalradio == "FirstName")

  {

  oController.namesort();

  }

 

  else if(globalradio == "EmployeeId")

 

  {

 

  oController.empidsort();

  }

 

  else if(globalradio == "Designation")

  {

  oController.designsort();

  }

 

 

controller coding:

 

  namesort:function(oEvent){

            

            var sort_array=new Array();

            var f_sort=new sap.ui.model.Sorter("FirstName");

            sort_array.push(f_sort);

            this.name_list=sap.ui.getCore().byId("m_lvlist");

            this.name_list.getBinding("items").sort(sort_array);

             },

            

empidsort:function(oEvent){

 

            var sort_array1=new Array();

            var id_sort=new sap.ui.model.Sorter("EmpNum");

            sort_array1.push(id_sort);

            this.id_list=sap.ui.getCore().byId("m_lvlist");

            this.id_list.getBinding("items").sort(sort_array1);

             },

            

designsort:function(oEvent)

             {

            var sort_array2=new Array();

            var design_sort=new sap.ui.model.Sorter("Designation");

            sort_array2.push(design_sort);

            this.design_list=sap.ui.getCore().byId("m_lvlist");

            this.design_list.getBinding("items").sort(sort_array2);

             },

 

 

Thanks & Regards,

Ramya


Viewing all articles
Browse latest Browse all 2638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>