[Chameleon] Table widget

Paul Spencer pagameba at magma.ca
Wed Sep 15 16:05:43 EDT 2004


I've just been working with the table widget and discovered that it 
really requires you to know the names of the columns of the data you are 
dealing with since you need to explicitly name them in the various 
templates.  I've updated the wiki page mentioned by Julien with the 
following example of working around this limitation.

------

One of the limitations of the Table widget is that it requires you to 
know the names of the columns in advance.  This is not always desirable, 
especially if you allow the user to build dynamic queries in some way.  
Until the Table widet supports a slightly more generic templating 
mechanism (see http://www.maptools.org/bugzilla/show_bug.cgi?id=672), 
the template pre-processor can be used to achieve this (not available in 
the service instance).  To do this, you will need to modify your 
application's 'phtml' file and your application's template.  In the 
'phtml' file, you need to be able to detect the column names that you 
want to display:

$aColNames = $_POST['aColNames']; //assumes that aColNames is coming 
from the POST variables, as would be the case with <select 
name="aColNames[]">

//this creates a string like <td>%<col1>%</td><td>%<col2>%</td>... as we 
would want it to appear in the <template> tag if we knew the column 
names in advance.

$szColHeader = "<td><b>%".implode( "%</b></td><td><b>%", $aColNames 
)."%</b></td>";
$szColBody = "<td>%".implode( "%</td><td>%", $aColNames )."%</td>";

//this comes after $oApp->CWCInitialize() but before $oApp->CWCExecute()

$oApp->setVar( "MyColumnHeader", $szColHeader );
$oApp->setVar( "MyColumnFooter", $szColBody );

Now in the application template, you would set up the templates 
something like:

<CWC2 Type="Table" Start="0" Count="10">
   <TEMPLATE Name="HEADER"><![CDATA[
<table>
  <tr>
  [$MyColumnHeader|<td>&nbsp;</td>$]
  </tr>
   ]]></TEMPLATE>
   <TEMPLATE Name="BODY"><![CDATA[
  <tr>
  [$MyColumnBody|<td>No Data Available!</td>$]
  </tr>
   ]]></TEMPLATE>
   <TEMPLATE Name="FOOTER"><![CDATA[
</table>
   ]]></TEMPLATE> 
</CWC2>

The syntax of the template pre-processor is [$<var>|<default value>$].  
If <var> is found in the form variables submitted to the page then the 
whole [$...$] block is replaced by the contents of the form variable.  
If it is not found, then it is replaced by the <default value>.  We can 
fake out the form variables by using $oApp->setVar( "<var>", "some 
value" ); between the CWCInitialize and CWCExecute steps of the 
chameleon process.


Julien-Samuel Lacroix wrote:

> Hi Berend,
>
> Look at:
> http://www.maptools.org/chameleon/wiki/Table
>
> It is the documentation for this widget.
>
> In short you need
> <cwc2 type="table" sharedresourcename="MyResult" >
>    <TEMPLATE Name="HEADER" Content="[html content]"/>
>    <TEMPLATE Name="BODY" Content="[html content]"/>
>    <TEMPLATE Name="FOOTER" Content="[html content]"/>
> </cwc2>
> The body part will be repeated and puted between the header and the 
> footer.
>
> Thanks
> Julien
>
> Berend Veldkamp wrote:
>
>> Hi,
>>
>> I'm looking for a (working) example of the table widget. Do I need 
>> anything more than this:
>>
>> <cwc2 type="SQLQuery" server="localhost" database="test" 
>> username="testuser" password="testpass" sqlquery="select * from 
>> testtable" sharedresourcename="MyResult">
>> </cwc2>
>>
>> <cwc2 type="table" start="0" count="10" sharedresourcename="MyResult" >
>> </cwc2>
>>
>>
>> Regards, Berend
>>
>>
>



More information about the Chameleon mailing list