Display Spreadsheet with simple sort options

Discussion in 'HTML & Website Design' started by Nerz, Jul 24, 2006.

  1. #1
    I have a spreadsheet thats now around 700 lines long with a series of columns. Id like to display this spreadsheet on a web page. Rather than exporting it as a webpage with interactivity via excel, which gives a whole bunch of options I dont want. I simply want to have a sort option alongside each column heading.

    So for instance

    Domain Name (Asc | Desc)
    value
    value
    etc...

    Ive seen this done with a series of database records, but im wondering if its possible with an xls spreadsheet.

    If your an excel guru id appreciate any feedback you might have.

    Nerz.
     
    Nerz, Jul 24, 2006 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    I have seen html tables exported by Excel. They are awfully bloated, and should really be cleaned up before publishing. I've only cleaned the outputted table, so have no advice on the best export method.

    You may take what you will from a table of football stats I compiled some time back. It uses javascript to sort by column either ascending or descending. The table is zebra striped with the sort column further differentiated.

    The javascript is fairly well commented. I can't take credit for the js, I got it somewhere myself.

    cheers,

    gary
     
    kk5st, Jul 24, 2006 IP
    Nerz likes this.
  3. Nerz

    Nerz Well-Known Member

    Messages:
    588
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    128
    #3
    That is basically exactly what i was after. Thx...your getting a little rep for that ;)

    It seems to work faultlessly ya?

    Hopefully ill be able to suss out the javascript...thats a fair whack of code.

    Thx again

    BTW if anyone has some ideas for getting the code length down a bit that would also be great.
     
    Nerz, Jul 25, 2006 IP
  4. Nerz

    Nerz Well-Known Member

    Messages:
    588
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Mmm i just realised that the code works well for unique values, but what if you have a lot of values the same?

    Say there cells at 10, two at 9, 8,7, three 6 etc..

    I can post the code in question but its mega long



    Anyone know a way of sorting identical values...
     
    Nerz, Jul 27, 2006 IP
  5. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #5
    There is a secondary column used to break ties.
    
        // Search the rows that follow the current one for a smaller value.
        for (j = i + 1; j < tblEl.rows.length; j++) {
          testVal = getTextValue(tblEl.rows[j].cells[col]);
          cmp = compareValues(minVal, testVal);
          // Negate the comparison result if the reverse sort flag is set.
          if (tblEl.reverseSort[col])
            cmp = -cmp;
          [color=red]// Sort by the second column (team name) if those values are equal.
          if (cmp == 0 && col != 1)
            cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                                getTextValue(tblEl.rows[j].cells[1]));[/color]
          // If this row has a smaller value than the current minimum, remember its
          // position and update the current minimum value.
          if (cmp > 0) {
            minIdx = j;
            minVal = testVal;
          }
        }
    
        // By now, we have the row with the smallest value. Remove it from the
        // table and insert it before the current row.
        if (minIdx > i) {
          tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
          tblEl.insertBefore(tmpEl, tblEl.rows[i]);
        }
      }
    Code (markup):
    Choose whichever column you want to be the tie-breaker. This is pretty common sort procedure; eg., if last names are the same, sort by first, if they're the same use middle and then the UID.

    cheers,

    gary
     
    kk5st, Jul 27, 2006 IP