Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:44:27+00:00 2026-05-23T15:44:27+00:00

I have a JSON array loaded into a JQuery mobile list. I have 4

  • 0

I have a JSON array loaded into a JQuery mobile list. I have 4 radio buttons to sort the list. All working.

Plus, I have a filter bar to search through the sorted results. So let’s say I sorted my list by price ascending, I can search the list with the filter bar. But if I click price descending, the list automaticaly refresh to default.

So what i’m trying to do is sort by name ascending, filter through the results with the search bar, and if I click another sort button, the list doesnt refresh.

I hope you can understand me, I explained this as clearly as I can. Heres my code :

var productList = {"products": [
    {"brand": "brand1", "description": "Product 1", "price": "03.25 "},
    {"brand": "brand2", "description": "Product 4", "price": "01.10 "},
    {"brand": "brand3", "description": "Product 3", "price": "04.21 "},
    {"brand": "brand4", "description": "Product 2", "price": "15.24 "},
    {"brand": "brand5", "description": "Product 5", "price": "01.52 "},
    {"brand": "brand6", "description": "Product 6", "price": "12.01 "},
    {"brand": "brand7", "description": "Product 7", "price": "05.24 "}

] };

$(document).ready(function() {

console.debug('ready');

$('#sort > input[type = "radio"]').next('label').click( function(event, el) {


    console.debug($(event.currentTarget).prev('input').attr('id'));

    sortID = $(event.currentTarget).prev('input').attr('id');

    refresh(sortID);
});

});

function refresh(sortID) {

var list = $("#productList").listview();
$(list).empty();

var prods = productList.products.sort(function(a, b) {

switch (sortID) {
case 'sort-a-z':
return a.description > b.description;

case 'sort-z-a':
return a.description < b.description;

case 'sort-price-up':
return parseInt(a.price) > parseInt(b.price);

case 'sort-price-down':
return parseInt(a.price) < parseInt(b.price);

default:
return a.description > b.description;

}

});
$.each(prods, function() {
list.append("<li>" + this.description + "  :       " + this.price + "</li>");
});

$(list).listview("refresh");

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:44:28+00:00Added an answer on May 23, 2026 at 3:44 pm

    I am not sure what is exactly the problem but I do know you shouldn’t be using parseInt to compare the prices like that.

    • parseInt stops when it sees a nondigit.
    • If the first character passed to parseInt is 0, then the string is evaluated in base 8 instead of base 10. In base 8, 8 and 9 are not digits, so parseInt(“08”) and parseInt(“09”) produce 0 as their result.

    parseInt can take a radix parameter, so that parseInt(“08”, 10) produces 8.

    for the best result use parseFloat and then multiply the result by 100 to produce a whole number – then when you’ll compare the prices you’ll avoid all quircks of the javascript floating point system.

    beyond that the code you shared looks okay to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have json array with a value that needs to be populated into an
i have a json array that i want to convert into a plain javascript
i have a json array var a_values = new Array(); a_values[AF:All] = new Array('KBL:Kabul','US:New
I have the following JSON Object being loaded into my application and stored into
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I have a two dimensional JSON array where each element contains several attributes. The
Hi I want to create a JSON array. I have tried using: JSONArray jArray
Hi I have a JSON object that is a 2-dimentional array and I need
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.