A dynamic table is a table its rows and columns created dynamically from tiddlers selected by some certain criteria. So, when a tiddler in the wiki meets such criteria will automatically create a new row in the table.
In a dynamic table a row also called a record is a tiddler and a column is a field or index of that tiddler. So in brief
A dynamic table is created by a dedicated macro as below
[tag[foo]]
"title tags created"
or [prefix[tb]]
which select all fields or indexes start with tb
Shiraz plugin has two macros to create a dynamic table
table-fd
to create dynamic tables from tiddlers fieldstable-id
to create dynamic tables from data tiddlers indexesDynamic tables have several features including
Dynamic tables in Shiraz is based on the great plugin TiddlyTables by Alan Aldrich, so all kodous goes to Alan.
Dynamic tables is a very simple with limited features comparing to TiddlyTables. Shiraz dynamic tables has some features not available in TiddlyTables 0.6.13 (at the time of release Dec 2019) like
These make Shiraz dynamic tables a simple and easy to use limited version of Tiddlywiki dynamic tables.
The table-fd
macro creates dynamic tables from tiddler fields. Rows (or recoreds) in such tables are constructed from tiddlers and columns from fields of those tiddlers. Each field creates a column in the table.
<<table-fd filter:"" fields:"" sortOp:"sort" caption:"" class:"" stateTiddler:"" footerRows:"">>
Attributes | Type | Description |
---|---|---|
filter | required | a filter to select tiddlers. A selected tiddler is called a record |
fields | optional | list of fields and special columns to be displayed. Fields are separated using spaces. Default value is all fields e.g. [fields[]] |
sortOp | optional | the sort operator used to sort column like sort , sortcs , nsort , nsortcs , sortan ... |
caption | optional | table caption, which is shown top left of table |
class | optional | a CSS class to customize table like thead-primary , table-hover-yellow , ... |
stateTiddler | optional | a tiddler title used for storing state data like toggling edit mode. Default value is stateDT |
footerRows | optional | an integer number greater than zero, indicates the number of rows in footer of table. These rows are used to insert numerical summaries for columns containing numerical values |
stateTiddler
parameter can be ignored if one dynamic table is created per tiddler. When there are several dynamic tables in the same tiddler, a unique state tiddler is required for each table to store different states used for proper operation.table-fd
macro creates a state tiddler by calling the qualify macro and prefixed them with $:/temp/dynamictables/
, so you can pass value like table01 as stateTiddler
parameter.There are special columns display contents in special format like
title
to display tiddler title as a linkcreated
to display the creation date of tiddlermodified
to display the modification date of tiddlertags
to display the tags of tiddlerUsing column template it possible to create more special column. One example is the email
column! It shows the content as a mailto
link.
Passing the tbl-expand
as a special column creates an extra column in displayed table. It adds a button to each table row, on click the text of tiddler is displayed in a new row. See examples.
Dynamic tables in Shiraz have two modes for displaying tables:
To toggle between the edit and view mode simple click on the and shown at the upper left corner of table
A dynamic table can be sorted using column data. To sort a table simply click on the column header. To toggle between ascending/descending order click again on the column header and note to arrows and appears in column header.
Create a simple dynamic table from tiddlers tagged with sample
and use title
, email
, created
and tag
fields.
<<table-fd filter:"[tag[sample]]" fields:"title email created tags" stateTiddler:"exmp01" caption:"''Table 1. Dynamic table example''">>
That renders as:
Sample data001 | kookma@nella.com | 2019.12.01 | |||||
Sample data002 | jeremy@nella.com | 2019.12.01 | |||||
Sample data003 | alan@nella.com | 2019.12.01 | |||||
Sample data004 | tony@nella.com | 2019.12.01 | |||||
Sample data005 | tara@nella.com | 2019.12.01 | |||||
Repeat Example i and add table-center
and thead-dark
as table classes. Also add two other fields fa
and fb
<<table-fd filter:"[tag[sample]]" fields:"title fa fb email created tags" stateTiddler:"exmp02" class:"table-center thead-dark" caption:"''Table 2. Dynamic table example''">>
That renders as:
Sample data001 | 5 | 1 | kookma@nella.com | 2019.12.01 | |||||||
Sample data002 | 4 | 6 | jeremy@nella.com | 2019.12.01 | |||||||
Sample data003 | 3 | 2 | alan@nella.com | 2019.12.01 | |||||||
Sample data004 | 8 | 7 | tony@nella.com | 2019.12.01 | |||||||
Sample data005 | 2 | 5 | tara@nella.com | 2019.12.01 | |||||||
Repeat Example i and add w-100
(to extend table width to 100% of parent container) and thead-dark
as table classes. Also add three other fields fa
and fb
and the special column tbl-expand
to show the toggle button for displaying the text field
<<table-fd filter:"[tag[sample]]" fields:"tbl-expand title fa fb email created tags" stateTiddler:"exmp03" class:"w-100 thead-dark" caption:"''Table 3. Dynamic table example''">>
That renders as:
Sample data001 | 5 | 1 | kookma@nella.com | 2019.12.01 | ||||||||
Sample data002 | 4 | 6 | jeremy@nella.com | 2019.12.01 | ||||||||
Sample data003 | 3 | 2 | alan@nella.com | 2019.12.01 | ||||||||
Sample data004 | 8 | 7 | tony@nella.com | 2019.12.01 | ||||||||
Sample data005 | 2 | 5 | tara@nella.com | 2019.12.01 | ||||||||
Shiraz has several table classes can be used for dynamic tables see Table Classes. It is possible to create user customized CSS classes and pass them to table-fd
macro.
The below example uses float right (float-right) which has 75% of tiddler width (w-75), with left margin setting (ml-3) and hover effect (table-hover-cyan) and info conceptual color header (thead-info).
<<table-fd filter:"[tag[sample]]" fields:"tbl-expand title fa fb email created tags" stateTiddler:"exmp04" class:"float-right ml-3 w-75 table-hover-cyan thead-info" caption:"''Table 4. Dynamic table example''">>
That renders as:
Sample data001 | 5 | 1 | kookma@nella.com | 2019.12.01 | ||||||||
Sample data002 | 4 | 6 | jeremy@nella.com | 2019.12.01 | ||||||||
Sample data003 | 3 | 2 | alan@nella.com | 2019.12.01 | ||||||||
Sample data004 | 8 | 7 | tony@nella.com | 2019.12.01 | ||||||||
Sample data005 | 2 | 5 | tara@nella.com | 2019.12.01 | ||||||||
The table-id
macro creates dynamic tables from data tiddler indexes. Rows (or records) in such tables are constructed from tiddlers and columns from indexes of those tiddlers. Each index creates a column in the table.
Both type of data tiddlers are supported
<<table-fi filter:"" indexes:"" sortOp:"sort" caption:"" class:"" stateTiddler:"" footerRows>>
Attributes | Type | Description |
---|---|---|
filter | required | a Tiddlywiki filter to select tiddlers as records |
indexes | optional | list of indexes and special column to be displayed. Indexes are separated using spaces. Default value is [indexes[]] which displays all indexes. |
sortOp | optional | the sort operator used to sort column like sort , sortcs , nsort , nsortcs , sortan ... |
caption | optional | table caption, which is shown top left of table |
class | optional | a CSS class to customize table like thead-primary , table-hover-yellow , ... |
stateTiddler | optional | a tiddler title used for storing state data like toggling edit mode. Default value is stateDT |
footerRows | optional | an integer number greater than zero, indicates the number of rows in footer of table. These rows are used to insert numerical summaries for columns containing numerical values |
stateTiddler
parameter can be ignored if one dynamic table is created per tiddler. When there are several dynamic tables in the same tiddler, a unique state tiddler is required for each table to store differnt states used for proper operation.table-id
macro creates a state tiddler by calling the qualify macro and prefixed them with $:/temp/dynamictables/
, so you can pass value like table01 as stateTiddler
parameter.There are special columns display contents in special format like
title
to display tiddler title as a linkcreated
to display the creation date of tiddlermodified
to display the modification date of tiddlertags
to display the tags of tiddlerUsing column template it possible to create more special column. One example is the email
column! It shows the content as a mailto
link.
Passing the tbl-expand
as a special column creates an extra column in displayed table. It adds a button to each table row, on click the text of tiddler is displayed in a new row. See examples.
Dynamic tables in Shiraz have two modes for displaying tables:
To toggle between the edit and view mode simple click on the and shown at the upper left corner of table
A dynamic table can be sorted using column data. To sort a table simply click on the column header. To toggle between ascending/descending order click again on the column header and note to arrows and appears in column header.
Create a simple dynamic table from tiddlers tagged with data
and use title
and tags
as special columns, and midterm
, homework
indexes.
<<table-id filter:"[tag[data]]" indexes:"title tags midterm homework" stateTiddler:"exmp01" caption:"''Table 1. Dynamic table from data tiddler''">>
That renders as:
Student001 | 87 | 100 | |||||
Student002 | 50 | 100 | |||||
Student003 | 39 | 80 | |||||
Student004 | 88 | 45 | |||||
Student005 | 90 | 83 | |||||
Student006 | 48 | 96 | |||||
Repeat Example i and add table-center
and thead-dark
as table classes. Also display term paper
and final
and remove special column tags
. Note that term paper
has spaces in title and should be passed as [[term paper]]
.
<<table-id filter:"[tag[data]]" indexes:"title midterm homework [[term paper]] final" stateTiddler:"exmp02" class:"table-center thead-dark" caption:"''Table 2. Dynamic table from data tiddler''">>
That renders as:
Student001 | 87 | 100 | 90 | 65 | |||||
Student002 | 50 | 100 | 93 | 79 | |||||
Student003 | 39 | 80 | 75 | 47 | |||||
Student004 | 88 | 45 | 84 | 87 | |||||
Student005 | 90 | 83 | 91 | 93 | |||||
Student006 | 48 | 96 | 85 | 60 | |||||
Repeat Example ii and add w-100
(to extend width to 100% of parent container) and thead-dark
as table classes. Also add the special column tbl-expand
to show toggle button for displaying the text field.
<<table-id filter:"[tag[data]]" indexes:"tbl-expand title midterm homework [[term paper]] final" stateTiddler:"exmp03" class:"w-100 thead-dark" caption:"''Table 3. Dynamic table from data tiddler''">>
That renders as:
Student001 | 87 | 100 | 90 | 65 | ||||||
Student002 | 50 | 100 | 93 | 79 | ||||||
Student003 | 39 | 80 | 75 | 47 | ||||||
Student004 | 88 | 45 | 84 | 87 | ||||||
Student005 | 90 | 83 | 91 | 93 | ||||||
Student006 | 48 | 96 | 85 | 60 | ||||||
Shiraz has several table classes can be used for dynamic tables see Table Classes. It is possible to create user customized CSS classes and pass them to table-id
macro.
The below example uses float right (float-right) which has 75% of tiddler width (w-75), with left margin setting (ml-3) and hover effect (table-hover-yellow) and warning conceptual color header (thead-warning).
<<table-id filter:"[tag[data]]" indexes:"tbl-expand title midterm homework [[term paper]] final" stateTiddler:"exmp04" class:"float-right w-75 ml-3 table-hover-yellow thead-warning" caption:"''Table 4. Dynamic table from data tiddler''">>
That renders as:
Student001 | 87 | 100 | 90 | 65 | ||||||
Student002 | 50 | 100 | 93 | 79 | ||||||
Student003 | 39 | 80 | 75 | 47 | ||||||
Student004 | 88 | 45 | 84 | 87 | ||||||
Student005 | 90 | 83 | 91 | 93 | ||||||
Student006 | 48 | 96 | 85 | 60 | ||||||
It is desired to be able to have summary rows to show some simple calculation on columns with numerical values. For example a column shows the scores of students for Chemistry course and one likes to compute the maximum, minimum, average, and median.
Shiraz dynamic tables support the below numerical macros
In a dynamic table containing footer rows, go to edit mode, in a footer cell of a desired column call the proper macro. For example to calculate average, enter <<average>>
. The below examples show how numerical summary can be inserted in footer rows of dynamic tables.
This example shows how numerical summaries can be added at the footer of a dynamic table created from tiddlers fields. In this example seven footer rows are give.
<$macrocall $name=table-fd filter="[tag[sample]]" class="table-hover-yellow" fields="title fa fb caption" stateTiddler="nella" caption="''Table 1. Dynamic table example''" footerRows="7"/>
That renders as:
Total | 5 | 5 | |||||
Minimum | 2 | 1 | |||||
Maximum | 8 | 7 | |||||
Sum | 22 | 21 | |||||
Product | 960 | 420 | |||||
Average | 4.4 | 4.2 | |||||
Median | 4 | 5 | |||||
Sample data001 | 5 | 1 | sina | ||||
Sample data002 | 4 | 6 | mita | ||||
Sample data003 | 3 | 2 | rana | ||||
Sample data004 | 8 | 7 | nella | ||||
Sample data005 | 2 | 5 | atro | ||||
This example demonstrate the use of numerical summary for a dynamic table from data tiddlers. It uses four footer rows to show, average, max, min, and median of numerical data in the column.
<<table-id filter:"[tag[data]]" indexes:"title midterm homework" stateTiddler:"lola" caption:"''Table 2. Dynamic table from data tiddler''" footerRows:"4">>
That renders as:
Student001 | 87 | 100 | |||
Student002 | 50 | 100 | |||
Student003 | 39 | 80 | |||
Student004 | 88 | 45 | |||
Student005 | 90 | 83 | |||
Student006 | 48 | 96 | |||
tabs
macro for tiddlers containing dynamic tables with numerical summaries needs special care. See demo/dynamic-tables/transclusion
When using tabs
macro or transclusion feature in Tiddlywiki, the definition of currentTiddler
variable will change and it depends to the scope.
Dynamic tables uses currentTiddler
variable to create a state tiddler to store the numerical summaries. When a tiddler contains a dynamic table is transcluded or used in a tabs
macro this causes error and dynamic table macros table-fd
and table-id
cannot show the numerical summary correctly.
To overcome these missuses do as bellow
Tiddlywiki itself recommend to use template with tabs macro, if one needs to use transclusion. See tabs macro. Simple pass the below template tiddler to tabs
macro
<$tiddler tiddler=<<currentTab>>>
<$transclude mode="block" />
</$tiddler>
In this tutorial, Tutorial Dynamic Tables has been created using this approach, it looks like below:
<<tabs tabsList:"[tag[dynamic-table]!tag[advanced]prefix[demo]]" default:"demo/dynamic-table-concept" class:"tc-horizontal" template:"$:/tabs/template">>
When a tiddler containing a dynamic table is transcluded, the transclusion causes the scope of currentVariable
changes, to keep it consistent, do as below
Use the $tiddler widget and wrap the transclusion. The tidname
referes to the tiddler title contains the dynamic tables.
<$tiddler tiddler="tidname">
<$transclude />
</$tiddler>
Use the $list widget and wrap the transclusion. The tidname
referes to the tiddler title contains the dynamic tables.
<$list filter="tidname">
<$transclude />
</$list>
See examples at examples/dynamic-tables/transclusion.
This demo shows how to customize the dynamic table footer when numerical summary is used.
The CSS selector for customizing the footer in dynamic tables is shiraz-dtable-footer
which is given in $:/plugins/kookma/shiraz/styles/dynamic-tables
Simply create a new tiddler tagged with $:/tags/Stylesheet
and set the desired properties. This way one can globally changes and customizes the feel and look of dynamic tables. For example to have red border and bold text do as below:
$:/tags/Stylesheet
.shiraz-dtable-footer tr td{
font-weight:bold;
color:red;
}
In the tiddler containg the dynamic table, use the style tag and set the desired properties for shiraz-dtable-footer
CSS selector. It is recommended to define a new class to prevent this customization applied to other tiddlers containing dynamic tables and at the same time are open in story river. See the below example.
Here a dynamic table footer is customized using the local style tag. A new class is defined here to prevent other dynamic tables in tiddlers opened in storu river affected.
<$macrocall $name=table-fd filter="[tag[student]]" class="my-footer-class" fields="caption score hospitality" stateTiddler=demo2 footerRows="2"/>
<style>
.my-footer-class .shiraz-dtable-footer tr td{
font-style:oblique;
color:maroon;
background:#FFFFDE;
}
</style>
That renders as:
Sum | 71 | 466 | |||
Average | 14.2 | 93.2 | |||
Anahita | 10 | 100 | |||
Misha | 18 | 95 | |||
Arta | 20 | 78 | |||
Hiva | 15 | 93 | |||
Kiara | 8 | 100 | |||
class
to table-fd
macroThe numerical summaries inserted in dynamic tables footer actually are some helper macros defined in:
table-fd
table-id
These macros can be overloaded locally or new macros can be defined and used.
To define a custom macro, use the following definitions
inputFilter
variable holds the dynamic table filtercurrentColumn
variable holds the column in which calculation is performedFor example to claculate the 0.25 of sum of all values in a column a new macro can be defined locally as below:
\define quartersum-fd() <$text text={{{ [subfilter<inputFilter>has<currentColumn>get<currentColumn>sum[]multiply[0.25]] }}}/> \end
\define quartersum-id() <$text text={{{ [subfilter<inputFilter>getindex<currentColumn>sum[]multiply[0.25]] }}}/> \end
table-fd
is used the fields are used to create a column.table-id
is used the indexes are used to create a column.So, different macros are required to be used with table-fd
and table-id
.
Then call it in a new dynamic table created using table-fd
or table-id
. Edit the below tables to see how they are used.
Quarter sum | 17.75 | 116.5 | |||
data001 | 10 | 100 | |||
data002 | 18 | 95 | |||
data003 | 20 | 78 | |||
data004 | 15 | 93 | |||
data005 | 8 | 100 | |||
Student001 | 87 | 100 | |||
Student002 | 50 | 100 | |||
Student003 | 39 | 80 | |||
Student004 | 88 | 45 | |||
Student005 | 90 | 83 | |||
Student006 | 48 | 96 | |||
This demo demonstrate how Shiraz dynamic tables can be used to create a simple but powerful task manager. To implement the task manager example, four new column templates are required, these are
and a special column template, called tbl-checkbox
which has two parts:
The task manager example only works with table-fd
but records (task tiddlers) can be any type of tiddlers.
To create a task manager using the shiraz dynamic table do as below
task
description
, priority
, status
, and due-date
table-fd
macro as below <$macrocall $name=table-fd filter="[tag[task]]" fields="tbl-checkbox tbl-expand tbl-delete title description priority status due-date tags" class="w-100" stateTiddler="your-state-tid"/>
The below example shows a simple task manager.
testData/tid001 | literature survey | very high | complete | 2020-02-13 | |||||||||
testData/tid002 | model development | high | rework | 2020-02-20 | |||||||||
testData/tid003 | computer implementation | very high | complete | 2020-02-27 | |||||||||
testData/tid004 | sensitivity study | normal | open | 2020-03-05 | |||||||||
testData/tid005 | final report | rework | 2020-04-13 | ||||||||||
A column template is tiddler contains preset format and script to display a content like fields, and indexes. For details on how templates work see Tiddlywiki template tiddlers.
Dynamic table uses templates for displaying the contents of fields and indexes. There are two type of column templates
For example to display the created date of a tiddler (record), a template like below is used
$:/plugins/kookma/shiraz/templates/dtable-body/created
<td>
<$view tiddler=<<currentRecord>> field=<<currentColumn>> format="date" template="YYYY.0MM.0DD"/>
</td>
Dynamic table column templates have the below specifications:
$:/tags/DynamicTable/Template
dtable-header/$(currentColumn)$
for header templatesdtable-fieldbody/$(currentColumn)$
for body templates in table-fd macro which creates dynamic tables from fieldsdtable-indexbody/$(currentColumn)$
for body templates in table-id macro which creates dynamic tables from indexesThe template shall process two modes
$edit-text
Template also must aware to toggle to view mode if a column is used for sorting table.
The below email template is used to display emails in dynamic tables from fields. It contains
$:/plugins/kookma/shiraz/templates/dtable-fieldbody/email
\define display-email-address()
<a class="tc-tiddlylink-external" href="mailto:$(currentRecord)$!!$(currentColumn)$" rel="noopener noreferrer" target="_blank">
<$transclude tiddler=<<currentRecord>> field=<<currentColumn>> mode="inline" />
</a>
\end
<$reveal type="nomatch" stateTitle=<<tempTableEdit>> stateIndex="mode" text="edit" tag="td">
<<display-email-address>>
</$reveal>
<$reveal type="match" stateTitle=<<tempTableEdit>> stateIndex="mode" text="edit" tag="td">
<!--check if the current column is not selected for sorting-->
<$list filter="[<tempTableSort>getindex[sortIndex]match<currentColumn>]" variable=ignore
emptyMessage="""<$edit-text tiddler=<<currentRecord>> field=<<currentColumn>> tag="input" class="shiraz-dtable-textbox"/>"""
>
<<display-email-address>>
</$list>
</$reveal>