on 10-31-2015 5:54 PM
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
Thanks all....
My list gets sorted correctly now. The problem was with the Odata. In the web service model, they had kept the 'EmpNum' field as Character field. After changing it to numeric field, the list gets sorted properly based on Employee id. Here's my coding:
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);
},
Regards,
Ramya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ramya,
Will this help? Plunker - ListSorting
Click on Sort by Employee ID radio, it sorts with respect to Employee ID.
Click on Sort by Name radio, it sorts with respect to Name.
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ramya,
Try like this:
var oSorter = new sap.ui.model.Sorter("EmpNum");
var oList = sap.ui.getCore().byId("m_lvlist");
var oBinding = oList.getBinding("items");
oBinding.sort(oSorter);
Just check in your model once, whether the field name that returns employee id is "EmpNum" or not.
Regards,
Sai Vellanki.
var id_sort=new sap.ui.model.Sorter("EmpNum");
id_sort.fnCompare = function(a, b){
var intA = parseInt(a), intB = parseInt(b);
if (intA == intB) {
return 0;
}
if (intA < intB) {
return -1;
}
if (intA > intB) {
return 1;
}
return 0;
};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please share your model data?
Thanks,
KA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is your EmpNum a numeric value ? does it have any non-numeric characters in it? if it has any non-numeric chars, then that's the reason. if it is only numeric values, then your model should return it as a int, float, decimal and your sorter shouldn't be a problem... if this continues, then you may need to parse into the correct numeric value in order be be able to sort your EmpNum values. an alternative would be to use the sort function in JavaScript hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.