Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    custom sort order

    Hi I have a table that sorts in jquery and I have one column that I would like to always remain the same while the other columns sort around it. What I want is for the order of the column to always be Great, Bad, Failure while every other column can be sorted and I don't want to the column to sort alphabetically. What is the easiert way for me to do this?

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts
    I'm a bit confused about your request.

    Can you provide an brief example of what the display should look like before and after sort?

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    an example would be:

    Fruit Color Shape
    ---------------------------------
    banana yellow long
    orange orange round
    apple red round
    grape purple round
    pear green oval

    What I would want to be able to do is keep the shape column the way it is but have all of the others be sortable so that apple, orange, and grape could be sorted alphabetically in the fruit and color columns but in the shape column it would always be long, round, oval.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by goofball1980 View Post
    an example would be:

    Fruit Color Shape
    ---------------------------------
    banana yellow long
    orange orange round
    apple red round
    grape purple round
    pear green oval

    What I would want to be able to do is keep the shape column the way it is but have all of the others be sortable so that apple, orange, and grape could be sorted alphabetically in the fruit and color columns but in the shape column it would always be long, round, oval.
    I'm still having problems with the concept.
    From your last post, if you sorted on fruit, you would expect?
    Fruit Color Shape
    ---------------------------------
    apple red long
    banana yellow round
    grape purple round
    orange orange round
    pear green oval
    or if you sorted on color, you would get?
    Fruit Color Shape
    ---------------------------------
    pear green long
    orange orange round
    grape purple round
    apple red round
    banana yellow oval
    Is that your idea?
    Last edited by jmrker; 01-01-2011 at 04:21 AM.

  • #5
    New Coder
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    no if you sorted on fruit I would expect:



    banana yellow long
    apple red round
    grape purple round
    orange orange round
    pear green oval

    and for color:

    banana yellow long
    orange orange round
    grape purple round
    apple red round
    pear green oval


    would an array be the best thing to use?
    Last edited by goofball1980; 01-02-2011 at 03:07 AM.

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Quote Originally Posted by goofball1980 View Post
    no if you sorted on fruit I would expect:



    banana yellow long
    apple red round
    grape purple round
    orange orange round
    pear green oval

    and for color:

    banana yellow long
    orange orange round
    grape purple round
    apple red round
    pear green oval


    would an array be the best thing to use?
    Why would a sort on fruit put "b"anana before "a"pple?
    and sort on color put "y"ellow before "o"range?

    I don't understand your definition of sort!

  • #7
    New Coder
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    A sort on fruit would put banana before apple because to maintain the order of the type column as long, round, oval banana would be first and the same for color

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb Specific order non-sorted sort display

    May not be as efficient as it could be,
    as it is a very specific display order request,
    but at least it does display a way to show a goofy kind of selected order non-sorted sort!
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Specific Ordered Sort </title>
    <script type="text/javascript">
    
    var Items = [
      ['banana','yellow','long'],
      ['orange','orange','round'],
      ['apple','red','round'],
      ['grape','purple','round'],
      ['pear','green','oval']
    ];
    
    function display(order) {
      var str = '';
      var tarr = [];
      for (var r=0; r<Items.length; r++) {
       str = Items[r][order]+',';
       str += Items[r].join(',');
       tarr.push(str);
      }
      tarr.sort();
      var tmp = [];
      str = '<table border="1"';
      str += '<tr><th>'+'Fruit,Color,Shape'.split(',').join('</th><th>')+'</th></tr>';
      var Shapes = ['Long','Round','Oval'];
      for (var i=0; i<Shapes.length; i++) {
        for (var r=0; r<tarr.length; r++) {
          tmp = tarr[r].split(',');
          if (tmp[3].toLowerCase() == Shapes[i].toLowerCase()) {
            tmp.shift();
            str += '<tr><td>'+tmp.join('</td><td>')+'</td></tr>';
          }
        }  
      }
      str += '</table>';
      document.getElementById('display').innerHTML = str;
    }
    
    </script>
    
    </head>
    <body>
    <select onchange="display(this.value)">
     <option value="">Select order</option>
     <option value="0">Fruits</option>
     <option value="1">Color</option>
    </select>
    <div id="display"></div>
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •