Question

I have table in websql to get data from that i am using JayData and write this

_context.FoodLog.include("FoodItem").orderByDescending("it.TotalCalories").toArray().then(function(foodLogs)
{
    $scope.$apply(function ()
    {
        try
        {
            for(var i=0; i<foodLogs.length; i++)
            {
                console.log(foodLogs[i].TotalCalories);                             
            }
        }
        catch(error)
        {
            console.log("Inner Try  "+error);
        }
    })
});

in console the result is

738.00
31.56           // why this 31.50 comes before 127.91 and 101.81
127.91
101.81
10.00
10.00

but it shows that result-set in not in specific order

Update Table Structure

$data.Entity.extend('SpookyHealthAppModel.FoodLog', {
'FoodLogID': { 'key':true,'type':'Edm.Int32','nullable':false,'computed':true },
'Quantity': { 'type':'Edm.String','maxLength':5 },
'TotalCalories': { 'type':'Edm.String','maxLength':10 },
'DateTime': { 'type':'Edm.DateTime' },
'ImageCol': { 'type':'Edm.String','maxLength':50 },
'Sync': { 'type':'Edm.Boolean' },
'FoodItem': { 'type':'SpookyHealthAppModel.FoodItem','required':true,'inverseProperty':'FoodLog' },
'User': { 'type':'SpookyHealthAppModel.User','required':true,'inverseProperty':'FoodLog' }
});
Was it helpful?

Solution

I found my problem :) According to my table structure my query works fine Because the field on which I put order by clause has String DataType and result is in order according to strings if I want result in numerical order change this line

'TotalCalories': { 'type':'Edm.String','maxLength':10 },

into this

'TotalCalories': { 'type':'Edm.Int32'}, // No need to define length now if you want in float then define float instead of int 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top