Results 1 to 13 of 13
  1. #1
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Sorting a webpage table

    This is a fairly obvious question, but if I want to get a webmaster to provide the ability to sort a multi-column table in a webpage on a single column, or two columns (by the latter I mean first on column c then on column f, say), by clicking on one of the column headings, what would he need to do? Must it be an ASP or PHP page, or could it be done by calling a program from within HTML?

    Thanks
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    John

    Not an area I have ventured into before and I am not sure how much data you will have in your table but there appears to be a javascript option as well

    Sort Table with Javascript
    Jerry

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    Thanks, Jerry

    The Word table I'm working on at present has 10 columns and 162 rows, and there are probably half a dozen sort options I would want included.

    Last time I looked though (pure) Javascript, I thought the sort facilities were very limited, so it seems that this chap has extended them in his JS program.

    I'll read more thoroughly through your link, to see if it will do what's wanted. Otherwise an option I thought of overnight would be to make the relevant column headings clickable, and then load a new webpage with the table already pre-sorted in the required order...
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting a webpage table

    John

    For what you want, your presorted option sounds like a very nice "lateral thinking" solution.

    If it does the job, why not?

    Back when I used to do that sort of stuff, I did things server side (using ASP back then)- but I needed a few more options than just sorting.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting a webpage table

    I often see this done with JavaScript and Ajax (JavaScript on steroids, Asynchronous JavaScript and XML). My company (employer I mean) has this available as a componenet that we can stuff into our web pages when we develop them, so it's already written for me. It lets me sort in ascending/descending any column and also decide how to do some sorts so that numbers appear before letters, etc. not just how it's layed out in an ASCII table which isn't usually how the end user wants to see it. You want to do it in-place and not through another server request to update the page (by doing a sort in a database and then sending the newly sorted data back to a new page)

    Do a search on 'sortable tables html' and you'll find lots of examples.

    Deb

  6. #6
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    Thanks to the contributors to this thread - I will investigate all these possibilities.

    I have been horrified to discover that saving a 400 KB Word .DOC file (itself ludicrously large for a simple table of less than 2000 cells) as .HTM format comes out at nearly a megabyte!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Sorting a webpage table

    Word's HTML output is very verbose. If you dig around in the Web Options dialog (I think it's under Tools>Options..., General) and saving as Filtered HTML, you might be able to get it down to a reasonable size. If not, you could use a macro to write out the table. The complications begin if you are shading alternate rows or otherwise require formatting information. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  8. #8
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting a webpage table

    If it's a simple table, you may want to try copying the table into Excel, and then saving as HTML.

    Removing formatting can help- for every cell formatted in a different way, there's a new style created.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  9. #9
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    Having tried Jerry's Sortable Sort-Table suggested link, I find it works quite well, requiring you to insert only a couple of statements and the JavaScript file.

    So minimally invasive (and sorts correctly on a column where the elements are prices in
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  10. #10
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    Glad it works, I was planning to use this also, I'll take this as a recommendation <img src=/S/cool.gif border=0 alt=cool width=15 height=15>
    Jerry

  11. #11
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    You can't suggest a program which will take a Word table and create decent (i.e fairly compact) HTML from it, can you? I'm going to try DreamWeaver tomorrow to see if it assists...

    I tried Geoff's suggestion of cutting the table from Word and pasting it to Excel, saving it as HTML page, but the results were differently horrible (compared with saving it as filtered HTML from Word!).

    The only complicated feature is that the first column of the table contains hyperlinked text, with the occasional non-hyperlinked piece of text in a smaller font after it. Like
    Just a dummy link with some smaller text following
    Subsequent columns are just plain ordinary text.

    I'm not too worried about an exact reproduction of all the table features; I just want to end up without line breaks in each cell!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  12. #12
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sorting a webpage table

    I used to do this with VBA. I used the VBA for a few different formatted cells, to get a very compact html table which approximated the Excel.

    I no longer have the original code, but this is a very elementary version of what I was doing. I was easily able to include fonts, background colours, borders and the like.

    <code>Sub createHTML()
    Dim rowNum As Integer
    Dim colNum As Integer

    Open "c:temp.htm" For Output As 1
    Print #1, "<html><title>Test output from Excel</title><body><table border=1>"
    For rowNum = 1 To 10
    Print #1, "<tr>"
    For colNum = 1 To 3
    Print #1, "<td>"
    Print #1, ActiveSheet.Cells(rowNum, colNum).Value
    Print #1, "</td>"

    Next colNum
    Print #1, "</tr>"
    Next rowNum
    Print #1, "</table></body></html>"
    Close #1
    End Sub</code>
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  13. #13
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sorting a webpage table

    Hi John

    I tend to use Notepad/TextPad/EditPlus or any text editor handy or of your choice and do what <!profile=MarkJ>MarkJ<!/profile> advised once and that was to do a find and replace for repetitive and laborious code changes. So for example if you had:

    <table>
    <tr>
    <td>John</br></td>
    <td>Jerry</br></td>
    </tr>
    </table>

    I would do a find/replace on </br></t to </t to remove the line breaks.

    The reason I do a part replace is in case there are other elements in the HTML which do not need to be changed.

    I absolutely detest HTML created by any Microsoft Office product unless I am doing something on the extreme hurry up and temporarily as the presentation of the code is best defined as awful. You can go for Dreamweaver if you like but you will almost certainly end up in the Code aspect and away from the WYSIWYG editor because of your use of javascript and the requirement to edit it....so it will be a glorified text editor.

    So if you are to do Jeff's option you will have to tidy it up in a text editor but be very careful as you can use the Clean Up Word HTML command in Dreamweaver but that rather scares me in case it strips out code I need <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>
    Jerry

Posting Permissions

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