Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] Sorting HTML tables solved (this time working)

Expand Messages
  • Ville Saalo
    ... Thanks. Your suggestion only works if the whole row consists of
    Message 1 of 5 , Sep 30, 2002
    • 0 Attachment
      >Nice work.
      >You might want to add this to the 'resort' clip:
      >^!Replace "^$StrFill({<th.*</th>}\s*;^%columns%)$" >> "^%order%" HIRAS
      >So that any headers get resorted along with the data they describe.


      Thanks.
      Your suggestion only works if the whole row consists of <TH's but not if only some
      columns are headers. Correct syntax would be this:

      ^!Replace "^$StrFill({<td|h.*</td|h>}\s*;^%columns%)$" >> "^%order%" HIRAS

      And as a third line of code has to be added

      ^!Inc %tds% ^$StrCount("<th";"^$GetSelection$";0;0)$


      >Using
      >^!Find "something or other"
      >^!Jump Select_Start
      >^!Set %r%=^$GetRow$
      >^!Set %c%=^$GetCol$
      >followed by later use:
      >^!SelectTo ^%r%:^%c%
      >
      >Is kind of clutzy.

      I though so too but couldn't come up with anything shorter. Maybe someone
      will enlighten us how to do this "right" if it can so be done?

      Some new ^!AutoSelect function might be handy, it would automatically store
      one location (that is the current cursor position [add some attribute to get the
      position of a selection ending, if some text is selected]) into %autoRow% and
      %autoCol% variables to where every empty ^!SelectTo would select to. Currently
      empty ^!SelectTo doesn't do anything (as far as I know..).

      That would replace my code

      ^!Find "</TABLE>" IS
      ^!Jump SELECT_START
      ^!Set %r%=^$GetRow$
      ^!Set %c%=^$GetCol$
      ^!Find "<TABLE" BIS
      ^!Select HTMLTAG
      ^!Jump SELECT_END
      ^!SelectTo ^%r%:^%c%

      with

      ^!Find "</TABLE>" IS
      ^!AutoSelect
      ^!Find "<TABLE" BIS
      ^!Select HTMLTAG
      ^!SelectTo E

      simplifying the code and removing three lines. The "E" after ^!SelectTo
      means "from the end of the current selection" (another new thing just invented
      by me ;)

      -Ville
    • h.paulissen@facburfdcw.unimaas.nl
      Hi Ville, ^!Find
      Message 2 of 5 , Sep 30, 2002
      • 0 Attachment
        Hi Ville,

        ^!Find </TABLE I
        ^!Set %End%=^$GetRowEnd$:^$GetColEnd$
        ^!Find <TABLE BI
        ^!SelectTo ^%End%

        I just saw these GetRowEnd as well as GetColEnd. Never noticed them before,
        but for this they come in very handy!

        Hugo

        >
        > ^!Find "</TABLE>" IS
        > ^!AutoSelect
        > ^!Find "<TABLE" BIS
        > ^!Select HTMLTAG
        > ^!SelectTo E
        >
        > simplifying the code and removing three lines. The "E" after
        > ^!SelectTo
        > means "from the end of the current selection" (another new
        > thing just invented
        > by me ;)
      • Michael Gerholdt
        Thanks, Hugo, for noticing and mentioning GetRowEnd etc. That goes a long way toward what I was after. In Internet Explorer there is the notion of InnerHTML
        Message 3 of 5 , Sep 30, 2002
        • 0 Attachment
          Thanks, Hugo, for noticing and mentioning GetRowEnd etc. That goes a long
          way toward what I was after.

          In Internet Explorer there is the notion of InnerHTML and OuterHTML.
          Thinking along those lines, and wanting to be able to re-use code for a
          variety of purposes and reflecting on the HTML table sorter Hugo and Ville
          have been crafting/perfecting:

          H="_SelectElement"
          ^!SetScreenUpdate OFF
          ^!If ^$IsEmpty(^%Tag%)$=0 Skip
          ^!Set %Tag%=^?{=_Table|h2|body|div}
          ^!If ^$IsEmpty(^%InOut%)$=0 Skip
          ^!Set %InOut%=^?{==Inner|Outer}
          ^!Clip ^%InOut%HTML
          ^!ClearVariable %InOut%
          ^!ClearVariable %Tag%

          H="_InnerHTML"
          ^!Find "</^%Tag%>" IS
          ^!Set %End%=^$GetRowStart$:^$GetColStart$
          ^!Find "<^%Tag%" BIS
          ^!Select HTMLTAG
          ^!Set %Beg%=^$GetRowEnd$:^$GetColEnd$
          ^!SetCursor ^%Beg%
          ^!SelectTo ^%End%

          H="_OuterHTML"
          ^!Find "</^%Tag%>" IS
          ^!Set %End%=^$GetRowEnd$:^$GetColEnd$
          ^!Find "<^%Tag%" BIS
          ^!Select HTMLTAG
          ^!Set %Beg%=^$GetRowStart$:^$GetColStart$
          ^!SetCursor ^%Beg%
          ^!SelectTo ^%End%

          You place a call to the first clip, _SelectElement (the list of html tags of
          course needs to be expanded).
          Call like this:

          ^!Set %InOut%="Inner";%Tag%="Table"
          ^!Clip SelectElement

          Or simply

          ^!Clip SelectElement

          to be prompted for HTML tag and choice between Inner and Outer HTML (no
          prompt in the first case).

          Once the first three are debugged and in working order, in future one would
          need write only one or two lines of code to be able to select inner or outer
          html of any (container) element. Using FarClip this could be useful from any
          clip library, including the HTML Table Sorter that Ville and Hugo have
          provided.

          Comments, improvements solicited!

          Mike
        • Ville Saalo
          Very nice work. :) Here s how I would improve it: H= _SelectElement ^!SetScreenUpdate OFF ^!If ^$IsEmpty(^%Tag%)$=0 Skip_5 ^!FIND
          Message 4 of 5 , Oct 1, 2002
          • 0 Attachment
            Very nice work. :) Here's how I would improve it:

            H="_SelectElement"
            ^!SetScreenUpdate OFF
            ^!If ^$IsEmpty(^%Tag%)$=0 Skip_5
            ^!FIND "</" IS
            ^!Jump SELECT_END
            ^!Select WORD
            ^!Set %Tag%=^$GetSelection$
            ^!Set %Tag%=^?{=_Table|^%Tag%|H2|Body|Div}
            ^!If ^$IsEmpty(^%InOut%)$=0 Skip
            ^!Set %InOut%=^?{==_Inner|Outer}
            ^!Clip ^%InOut%HTML
            ^!ClearVariable %InOut%
            ^!ClearVariable %Tag%

            Notice how it's now easy to select the element in which you currently
            are. That isn't an idiotproof solution as if the starting tag is after
            our cursor's beginning place it obviously doesn't surround the text
            the cursor was on, but anyway. I have actually made a clip which can
            select any tag correctly, look for the Surrounding.zip (.clb) under the
            HTML Libraries at NoteTab's homepage. It's one of my first serious
            clips and/so it looks rather ugly (35 lines of code + some blank lines
            + comments...) but I should now be able to improve it. Uhh, now I'm
            completely off-topic, sorry. :)

            I still left the underscore in front of the Table -choice as we're
            working with them. I also added an underscore in front of the
            Inner|Outer -selection.

            Another thing I noticed here is that the ^!Select HTMLTAG command
            actually has a bug: create an empty document and insert some simple
            table. There should be nothing above the starting tag. Now try
            selecting the inner html of the table, either with my original clip or
            Mike's improved clip. They both fail, selecting the inner html *and* the
            starting <TABLE -tag. It's a bit disturbing...

            -Ville




            -----Original Message-----
            From: Michael Gerholdt <keywordz@...>
            To: ntb-clips@yahoogroups.com <ntb-clips@yahoogroups.com>
            Date: Tuesday, October 01, 2002 6:49 AM
            Subject: Re: [Clip] Sorting HTML tables solved (this time working)


            >Thanks, Hugo, for noticing and mentioning GetRowEnd etc. That goes a long
            >way toward what I was after.
            >
            >In Internet Explorer there is the notion of InnerHTML and OuterHTML.
            >Thinking along those lines, and wanting to be able to re-use code for a
            >variety of purposes and reflecting on the HTML table sorter Hugo and Ville
            >have been crafting/perfecting:
            >
            >H="_SelectElement"
            >^!SetScreenUpdate OFF
            >^!If ^$IsEmpty(^%Tag%)$=0 Skip
            >^!Set %Tag%=^?{=_Table|h2|body|div}
            >^!If ^$IsEmpty(^%InOut%)$=0 Skip
            >^!Set %InOut%=^?{==Inner|Outer}
            >^!Clip ^%InOut%HTML
            >^!ClearVariable %InOut%
            >^!ClearVariable %Tag%
            >
            >H="_InnerHTML"
            >^!Find "</^%Tag%>" IS
            >^!Set %End%=^$GetRowStart$:^$GetColStart$
            >^!Find "<^%Tag%" BIS
            >^!Select HTMLTAG
            >^!Set %Beg%=^$GetRowEnd$:^$GetColEnd$
            >^!SetCursor ^%Beg%
            >^!SelectTo ^%End%
            >
            >H="_OuterHTML"
            >^!Find "</^%Tag%>" IS
            >^!Set %End%=^$GetRowEnd$:^$GetColEnd$
            >^!Find "<^%Tag%" BIS
            >^!Select HTMLTAG
            >^!Set %Beg%=^$GetRowStart$:^$GetColStart$
            >^!SetCursor ^%Beg%
            >^!SelectTo ^%End%
            >
            >You place a call to the first clip, _SelectElement (the list of html tags of
            >course needs to be expanded).
            >Call like this:
            >
            >^!Set %InOut%="Inner";%Tag%="Table"
            >^!Clip SelectElement
            >
            >Or simply
            >
            >^!Clip SelectElement
            >
            >to be prompted for HTML tag and choice between Inner and Outer HTML (no
            >prompt in the first case).
            >
            >Once the first three are debugged and in working order, in future one would
            >need write only one or two lines of code to be able to select inner or outer
            >html of any (container) element. Using FarClip this could be useful from any
            >clip library, including the HTML Table Sorter that Ville and Hugo have
            >provided.
            >
            >Comments, improvements solicited!
            >
            >Mike
          • Michael Gerholdt
            Ville, I like the improvement and will use it. Hmmm, most of my tables aren t consistent from row to row. stuf stuf
            Message 5 of 5 , Oct 2, 2002
            • 0 Attachment
              Ville,

              I like the improvement and will use it.

              Hmmm, most of my tables aren't consistent from row to row.

              <TR>
              <TD>stuf</TD>
              <TD colspan="2">stuf</TD>
              </TD>stuf</TD>
              </TR>

              <TR>
              <TD>stuf</TD>
              </TD>stuf</TD>
              <TD>stuf</TD>
              </TD>stuf</TD>
              </TR>

              The first row doesn't get sorted. This looks interesting.

              But last night was miles before sleep. Tonight, it's sleep before miles.

              Sleep is lovely dark and deep
              and i've no promises to keep . . .

              'night, with apologies to R.F.

              Thanks,
              Mike
            Your message has been successfully submitted and would be delivered to recipients shortly.