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.
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
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.
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...
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