Sorting the Data with String,Integers and Decimals using Javascript
Main Logic for Sorting:
Sorting with String :
function SortByName(x, y) { return ((x.winename == y.winename) ? 0 : ((x.winename > y.winename) ? 1 : -1)); }Sorting with Integers :
function SortByPrice(x, y) { return parseFloat(y.price) - (x.price); }Sorting with Decimals:
function SortByRating(x, y) { return ((y.reviewstars == x.reviewstars) ? 0 : ((y.reviewstars > x.reviewstars) ? 1 : -1)); }Complete Logic :
Following is the code to bind the data to listview based sorting requested from json.
ID:' + wine.uniqueid + '.
' +
'Price :' + wine.price + '
' +
'Review Stars :' + wine.reviewstars + '
' +
'Review Text:' + wine.reviewtext + '
' +
'
');
}
$('#completeWines').listview('refresh');
});
});
});
That's it. If you any queries.Please drop a message.
$('#BindWines').live('pageshow', function() { $('#completeWines li').remove(); jQuery.getJSON("Js/newwinecurrent.json", function(data) { wines = data.rows; if (query_string[0] == "Price") { wines.sort(SortByPrice); } else if (query_string[0] == "Rating") { wines.sort(SortByRating); } else { wines.sort(SortByName); } $.each(wines, function(index, wine) { if (parseInt(wine.price) >= parseInt(subpar1) && wine.reviewstars >= subpar2) { $('#completeWines').append('
Labels: .Net Tutorials, HTML5, javascript, JQuery
2 Comments:
Hello There. I found your blog using msn. This is an extremely well written article.
I'll be sure to bookmark it and come back to read more of your useful information. Thanks for the post. I will definitely comeback.
Also visit my weblog - more info - www.myhack24.com -
Great tutorial. This will be very helpful for the developers. One of my friend is looking for the same kind of solution and I am going to provide this link to him. Thanks for sharing this here with us.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home