cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting of Numbers in XML View is not working

Firoz_Ashraf
Contributor
0 Kudos
1,520

Hi,

Sorting of Numbers in my XML View is not working.

I have searched the forum and got to know that JSON treats all as characters.

Some post were referencing to use sap.ui.model.Sorter and fnCompare

My view is an XML view. How do I use this or is there any other solution?

Here is my XML Code for table column on which I want the sorting.



<Table:Column hAlign="Right" width="10em" sortProperty="Kwmeng" filterProperty="Kwmeng">

     <Table:label>

          <Label text="Order Quantity" />

     </Table:label>

     <Table:template>

          <Label text="{  path:'SalesModel>Kwmeng',type:'sap.ui.model.type.Float'}" />

     </Table:template>

</Table:Column>

Any help would be highly appreciated.

Regards,

Firoz.

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Firoz,

You might be having it in string format. Try converting to float using parseFloat() before binding.

Will this sample help? Plunker


Regards,

Sai Vellanki.

Firoz_Ashraf
Contributor
0 Kudos

Thanks Sai,

As suggested by you I converted the string format using parseFloat() and sorting issue got solved !

Here is my code for conversion:


oModel.read('/openorderSet',null,[fltr],false,function(oData){

  for (var i = 0; i < oData.results.length; i++) {

             var oOrdQty = parseFloat(oData.results[i].Kwmeng);

             oData.results[i].Kwmeng = oOrdQty;

           }

  oJsonModel.setData(oData);

  sap.ui.getCore().setModel(oJsonModel, "SalesModel");

  },function(){

                alert("Read failed for order item"); 

                });

Many Thanks,

Firoz.

Answers (1)

Answers (1)

Former Member
0 Kudos

Did you go through the documentaions?

Step 25: Sorting and Grouping

Regards

Firoz_Ashraf
Contributor
0 Kudos

Hi,

Yes, I have gone through the documentation that you have mentioned.

The issue is not with character sorting. Problem is with numeric sorting.

Further, I am using sap.ui.table

Former Member
0 Kudos

its working fine for me check sample

JS Bin - Collaborative JavaScript Debugging

I think you are getting numbers in string format from OData service.You may have to convert into number using some javascript functions.for eg: parseInt

Regards

Firoz_Ashraf
Contributor
0 Kudos

Hi Rajesh,

In your case the data that you are taking for number is "number". Whereas, in my case when the data is returned back from back-end SAP system through oData it treats number as "Character". Please see the screen shot.

Regards,

Firoz.