Tags:
create new tag
, view all tags

SID-02261: Using Table within Search

Status: Answered Answered TWiki version: 6.0.1 Perl version:
Category: TablePlugin Server OS: Last update: 1 year ago

I'm struggling with understanding what I am doing wrong trying to use TABLE within a SEARCH.

I would like to create a "new" table when a certain condition is met. This appears to work successfully however I'm unable to figure out how to format each table. Hopefully this is demonstrated in the example below:

%SEARCH{"META:FORM.*[U]serForm;META:FIELD.*[F]irstName.*value=\"BobB.*" web="%USERSWEB%" type="regex" nonoise="on" 
format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $dollarpercntTABLE{columnwidths=\"300px\"}$dollarpercnt $n | *Name* | $n | $topic |, | $topic | )}$percnt" 
excludetopic="TWiki*"}%

The results from the search above are shown below:


$percntTABLE{columnwidths="300px"}$percnt
Name
BobbiMaluga

$percntTABLE{columnwidths="300px"}$percnt
Name
BobbiMarker

$percntTABLE{columnwidths="300px"}$percnt
Name
BobbieKeane
BobbyBothmann
BobbyBrown
BobbyChipping
BobbyHedge
BobbyJack

$percntTABLE{columnwidths="300px"}$percnt
Name
BobbyNGUYEN
BobbyNixon

$percntTABLE{columnwidths="300px"}$percnt
Name
BobbyRiawan
BobbyRodriguez
BobbyRomanski
BobbySmither

-- Jani Hamalainen - 2016-10-12

Discussion and Answer

Not sure what your objective is with this search, but it looks like you run into escape hell with:

format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $dollarpercntTABLE{columnwidths=\"300px\"}$dollarpercnt $n | Name | $n | $topic |, | $topic | )}$percnt"

With your format, $percntCALCULATE{}$percent is delayed until after the SEARCH, as you intended. However, $dollarpercntTABLE{}$dollarpercnt resolves to $percntTABLE{}$percnt after SEARCH. The CALCULATE does not resolve the $percnt. If you want to delay that and resolve by CALCULATE you can escape it CALCULATE specific:

format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $NOP(%)TABLE{columnwidths=\"300px\"}$NOP(%) $n | Name | $n | $topic |, | $topic | )}$percnt"

The $NOP(%)TABLE{columnwidths=\"300px\"}$NOP(%) resolves to $NOP(%)TABLE{columnwidths="300px"}$NOP(%) after SEARCH, and to %TABLE{columnwidths="300px"}% after CALCULATE.

-- Peter Thoeny - 2016-10-13

Thanks for the explanation Peter. I did intentionally include the extra $dollar surrounding the TABLE because I was trying to demonstrate that I would like the TABLE to be added whenever the $IF statement was true. Sorry that I forgot to mention it thought but I felt removing the $dollar made the output a lot more confusing (and less clear what I was trying to do).

I did try what you had suggested though and followed through your explanation. It didn't occur to me before that SEARCH finished prior to CALCULATE when using $percnt. The results are still not exactly what I was looking for but maybe I can figure it out from here. My goal is to visible see a new table (and allow formatting) when the $IF condition is met.


| Name |
| Name |
| Name |
| Name |
| Name |
BobbiMaluga
BobbiMarker
BobbieKeane
BobbyBothmann
BobbyBrown
BobbyChipping
BobbyHedge
BobbyJack
BobbyNGUYEN
BobbyNixon
BobbyRiawan
BobbyRodriguez
BobbyRomanski
BobbySmither

-- Jani Hamalainen - 2016-10-13

I couldn't figure out how to integrate the TABLE function into the SEARCH (as shown above) so I took the approach of changing the CSS to display the table like I desired.

A brief summary for anyone else with a similar desire:

  • Add the CSS to your topic:
<style>
.MyTable .twikiTable {
    width: 100%;
    vertical-align: middle;
    text-align: center;    
}
.MyTable .twikiTable tr {
    vertical-align: middle;
    text-align: center;    
}
.MyTable .twikiTable td {
    vertical-align: middle;
    text-align: center;    
}
</style>
  • Enclose your search results within a div class = MyTable (or whatever you name the class in the CSS).
<div class="MyTable">
%SEARCH{"META:FORM.*[U]serForm;META:FIELD.*[F]irstName.*value=\"BobB.*" web="%USERSWEB%" type="regex" nonoise="on" 
format="$percntCALCULATE{$IF($LENGTH($topic) == 11, $n --- $n $dollarpercntTABLE{columnwidths=\"300px\"}$dollarpercnt $n | *Name* | $n | $topic |, | $topic | )}$percnt" 
excludetopic="TWiki*"}%
</div>

-- Jani Hamalainen - 2016-10-25

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title Using Table within Search
SupportCategory TablePlugin
TWiki version 6.0.1
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2016-10-25 - JaniHamalainen
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.