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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Location
    London
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Newbie stuck with code

    Hi,

    First time here, so I'm sorry if its really rusty what I'm asking.

    I found a code to use from ajaxdaddy.com and edited what I wanted in the table instead but once I went to preview my work, it didn't work out as planned.

    Can anyone please help me correct it.

    Code:
    <html><head>
    <base href="http://www.ajaxdaddy.com/media/demos/play/1/table-organize/table-organize/" />
    <title>NoFunc: Playlists</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <scriptsrc="javascript/tableorganize.js" type="text/javascript"></script>
    <scriptsrc="javascript/tableorganize_example.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" media="all" href="css/tableorganize.css" />
    </head><body id="body">
    
    <center>
    <table id="table" onselectstart="return false" cellspacing="0">
    <thead>
    <tr class="asc" id="head">
       <th style="width: 20px;">#</th>
       <th style="width: 150px;">Team<span></span></th>
       <th style="width: 20px;">Pld<span></span></th>
       <th style="width: 20px;">W<span></span></th>
       <th style="width: 20px;">D<span></span></th>
       <th style="width: 20px;">L<span></span></th>
       <th style="width: 20px;">F<span></span></th>
       <th style="width: 20px;">A<span></span></th>
       <th style="width: 20px;">GD<span></span></th>
       <th style="width: 20px;">Pts<span></span></th>
      </tr>
    </thead>
     <tbody id="tbody">
    <tr class="odd"><td>1</td><td>FC Bullbrook</td><td>6</td><td>6</td><td>0</td><td>0</td><td>29</td><td>4</td><td>25</td><td>18</td></tr>
    <tr class="even"><td>2</td><td>Real Leisure</td><td>4</td><td>4</td><td>0</td><td>0</td><td>14</td><td>3</td><td>11</td><td>12</td></tr>
    <tr class="odd"><td>3</td><td>The Untouchables</td><td>5</td><td>3</td><td>1</td><td>1</td><td>22</td><td>5</td><td>17</td><td>10</td></tr>
    <tr class="even"><td>4</td><td>Guns n Showboats</td><td>5</td><td>3</td><td>1</td><td>1</td><td>16</td><td>8</td><td>8</td><td>10</td></tr>
    <tr class="odd"><td>5</td><td>The Gimps</td><td>6</td><td>3</td><td>0</td><td>3</td><td>20</td><td>12</td><td>8</td><td>9</td></tr>
    <tr class="even"><td>6</td><td>Still Waiting for Sam THP</td><td>5</td><td>3</td><td>0</td><td>2</td><td>18</td><td>13</td><td>5</td><td>9</td></tr>
    <tr class="odd"><td>7</td><td>The A Team</td><td>4</td><td>2</td><td>0</td><td>2</td><td>7</td><td>14</td><td>-7</td><td>6</td></tr>
    <tr class="even"><td>8</td><td>Honkey Donkeys</td><td>6</td><td>2</td><td>0</td><td>4</td><td>10</td><td>18</td><td>-8</td><td>6</td></tr>
    <tr class="odd"><td>9</td><td>AFC Leisure</td><td>4</td><td>1</td><td>0</td><td>3</td><td>7</td><td>12</td><td>-5</td><td>3</td></tr>
    <tr class="even"><td>10</td><td>GTF Eagles</td><td>6</td><td>1</td><td>0</td><td>5</td><td>10</td><td>22</td><td>-12</td><td>3</td></tr>
    <tr class="odd"><td>11</td><td>NPL FC</td><td>1</td><td>0</td><td>0</td><td>1</td><td>0</td><td>5</td><td>-5</td><td>0</td></tr>
    <tr class="even"><td>12</td><td>Crowthorne FC</td><td>6</td><td>0</td><td>0</td><td>6</td><td>6</td><td>43</td><td>-37</td><td>0</td></tr>
    </tbody>
    </table></center>
    
    <script type="text/javascript">
    
    document.onkeydown=function(e){ kRun(e,Array(37,38,39,40),function(k) { var v=((k==40||k==39)?1:-1); iSW('this',Tr[Math.min(Trl,Math.max(0,$('this').rowIndex+v-1))]); }); };
    document.onkeyup=function(){ stopK[0]=1; };
    
    /* GLOBALS */
    
    var T=$('table'), Tb=T.tBodies[0], Tr=Tb.rows, Trl=Tr.length-1, stop=0, stopTH=0, stopK='', cur=''; trMAP(0,'',1); thMouse($T('th','head'),Array(0,10));
    
    </script>
    </body></html>
    What I've been trying to do is when I click on a header it sorts out the listings to the desired heading, but it doesn't seem to sort, and when I had managed to sort something, it never does it properly, it seems to sort to one digit (ie 1, 10, 11, 2, 3, 4, 5)..

    Sorry if its not explained well enough. Its the first time I've ventured into AJAX after spending most of my time with simple HTML.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,166
    Thanks
    23
    Thanked 601 Times in 600 Posts
    I have used the code on this page to sort tables>
    http://www.kryogenix.org/code/browser/sorttable/ I liked it and it does the job.

  • Users who have thanked sunfighter for this post:

    ladbroke (05-09-2012)


  •  

    Posting Permissions

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