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 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb need sorting table

    i haven't been able to find a sorting table that could properly sort what i want
    here is what i want it to sort
    the list is sorted by position
    NAME______ID____Lvl_____Rank____Position

    Maha_____19923__100_____100____Owner
    Thrawl____9550___159_____100____Co-Owner
    marhanen_22304___83_____ 99_____Banker
    etc.
    i need one that could sort it and a way so that i could sort by position with it in a certain order.

    thanks
    Marhanen
    Last edited by marhanen; 05-03-2006 at 04:03 AM. Reason: make spaces inbetween

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Something like this? (see also attachment)
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Sortare ascendenta/descendenta pe coloane</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    style type="text/css">
    <!--
    tr {
        
    background-color#CCCCCC;
    }
    .
    tr1 {
        
    background-color#F5F5F5;
    }
    .
    tr2 {
        
    background-color#E5E5E5;
    }
    .
    point {
     
    cursor:pointer;
    }
    -->
    </
    style>
    <
    script type="text/JavaScript">
    //Genuine code by Corneliu Lucian 'KOR' Rusu  -- mailto:cornel@apropo.ro
    function sortIt(w){
    var 
    r=w.parentNode.parentNode.getElementsByTagName('tr');
    var 
    oRows = new Array()//clone lines
    var iRows = new Array()//index lines
    for(var i=1;i<r.length;i++){
    oRows[i]=r[i].cloneNode(true);
    iRows[i]=r[i].rowIndex;
    }
    var 
    q=w.cellIndex;
    var 
    oCol = new Array()
    var 
    vCol = new Array()
    for(var 
    i=0;i<iRows.length;i++){
    var 
    r[i].cells[q].firstChild.nodeValue;
    if(
    Number(v)){v=Number(v)}
    oCol[i]=[v,iRows[i]];
    vCol[i]=[v,iRows[i]];
    }
    oCol.shift();
    vCol.shift();
    sCol oCol.sort(function(oCol,sCol){return oCol[0] == sCol[0] ? : (oCol[0] < sCol[0] ? -1)});
    if(
    vCol.toString()==sCol.toString()){sCol.reverse()}// switch down/up
    var q=1;
    for(var 
    i=1;i<r.length;i++){//rewrite lines
    r[i].parentNode.replaceChild(oRows[sCol[i-1][1]],r[i]);
    //START zebra
    q=(q>2)?1:q
    r
    [i].className='tr'+q;q++;
    // END zebra
    }
    //switch arrows
    var =['desc.gif','cres.gif','none.gif'];//arrows url
    var allS =r[0].getElementsByTagName('img');
    var 
    sag w.getElementsByTagName('img')[0];
    var 
    url =(sag.getAttribute('src').indexOf(s[1])>-1||sag.getAttribute('src').indexOf(s[2])>-1)?s[0]:s[1];
    sag.setAttribute('src',url);
    for(var 
    i=0;i<allS.length;i++){//init arraows
    if(allS[i]!=sag){allS[i].setAttribute('src',s[2])}
    }
    }
    </script>
    </head>
    <body>
    <table width="400" border="0" cellspacing="2" cellpadding="2">
    <tbody>
    <tr> 
    <td class="point" onclick="sortIt(this)" title="Sort"><strong>NAME</strong> <img src="none.gif" border="0" alt=""></td>
    <td class="point" onclick="sortIt(this)" title="Sort"><strong>ID</strong> <img src="none.gif" border="0" alt=""></td>
    <td class="point" onclick="sortIt(this)" title="Sort"><strong>Lvl</strong> <img src="none.gif" border="0" alt=""></td>
    <td class="point" onclick="sortIt(this)" title="Sort"><strong>Rank</strong> <img src="none.gif" border="0" alt=""></td>
    <td class="point" onclick="sortIt(this)" title="Sort"><strong>Position</strong> <img src="none.gif" border="0" alt=""></td>
    </tr>
    <tr class="tr1"> 
    <td>Maha</td>
    <td>19923</td>
    <td>100</td>
    <td>100</td>
    <td>Owner</td>
    </tr>
    <tr class="tr2"> 
    <td>Thrawl</td>
    <td>9550</td>
    <td>159</td>
    <td>100</td>
    <td>Co-Owner</td>
    </tr>
    <tr class="tr1"> 
    <td>Marhanen</td>
    <td>22304</td>
    <td>83</td>
    <td>99</td>
    <td>Banker</td>
    </tr>
    </tbody>
    </table>
    </body>
    </html> 
    Attached Files Attached Files
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks that worked


  •  

    Posting Permissions

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