table_class
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
table_class [2019/12/21 21:43] – created sahl | table_class [2021/03/18 21:20] (current) – sahl | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Table class ====== | ====== Table class ====== | ||
- | This is a PHP wrapper for the tabulator | + | Table is a PHP wrapper for the Tabulator |
===== A basic table ===== | ===== A basic table ===== | ||
Line 9: | Line 9: | ||
<code php> | <code php> | ||
$table = new Table(); | $table = new Table(); | ||
- | // The setOption | + | // The setTabulatorOption |
- | $table->setOption(' | + | $table->setTabulatorOption(' |
- | $table->setOption(' | + | $table->setTabulatorOption(' |
// This renders the necessary html | // This renders the necessary html | ||
$table-> | $table-> | ||
Line 18: | Line 18: | ||
===== Datarecord convenience ===== | ===== Datarecord convenience ===== | ||
- | One can quickly build a column definition | + | There are three main ways to integrate [[Datarecord class|Datarecord]] objects into a table. The easiest and most convenient is using the [[DatarecordEditComplex class]] which automatically both creates a table of data, and adds the options to create, edit and delete such data. |
+ | |||
+ | Stepping down a notch is the '' | ||
+ | |||
+ | The most manual way to get data from a Datarecord is as follows, where you also need to construct and provide your own data url. | ||
+ | |||
+ | <code php index.php> | ||
+ | $table = new Table(); | ||
+ | $table-> | ||
+ | $table-> | ||
+ | $table-> | ||
+ | </ | ||
+ | |||
+ | <code php data.php> | ||
+ | // Get all data | ||
+ | $filter = new Filter(DATARECORD CLASS NAME); | ||
+ | $collection = $filter-> | ||
+ | |||
+ | $result = Table:: | ||
+ | |||
+ | header(' | ||
+ | echo json_encode($result); | ||
+ | </ | ||
+ | |||
+ | ===== Filtering data ===== | ||
+ | |||
+ | For both the DatarecordEditComplex and the getTableForClass configuration above, there is an easy built-in way to filter data, and that is by attaching a filter to the table like this: | ||
+ | |||
+ | <code php> | ||
+ | $filter = new Filter(DATARECORD CLASS NAME); | ||
+ | $filter-> | ||
+ | |||
+ | $table-> | ||
+ | </ | ||
+ | |||
+ | This will apply the filter to the table when displaying. | ||
+ | |||
+ | If you provide your own data url, you can also easily modify it to comply to such a filter. Just decode it from the POST like this: | ||
+ | |||
+ | <code php> | ||
+ | $filter = Filter:: | ||
+ | </ | ||
+ | |||
+ | which will yield the same filter as passed into the table. | ||
+ | |||
+ | ===== Actionbuttons ===== | ||
+ | |||
+ | As a convenience one can easily add an // | ||
+ | |||
+ | < | ||
+ | $table-> | ||
+ | </ | ||
+ | |||
+ | The following will add an icon of an open envelope on each row, and each time it is clicked, the javascript function '' | ||
+ | |||
+ | ===== Selecting items ===== | ||
+ | |||
+ | In order to display checkboxes next to each data row, one can call the '' | ||
+ | |||
+ | <code php> | ||
+ | $table-> | ||
+ | </ | ||
+ | |||
+ | This will render checkboxes next to each table row. | ||
+ | |||
+ | These checked values can be retrieved from javascript using the '' | ||
+ | |||
+ | ===== Providing a search form ===== | ||
+ | |||
+ | It is possible | ||
+ | |||
+ | <code php> | ||
+ | $form = new Form(' | ||
+ | |||
+ | $table-> | ||
+ | $table-> | ||
+ | </ | ||
+ | |||
+ | This will prevent the table from displaying data before the form is submitted and the content of the form will be posted to the data URL, so one can perform the search server side: | ||
+ | |||
+ | <code php data.php> | ||
+ | ... | ||
+ | $filter = new Filter(DATARECORD CLASS NAME); | ||
+ | $form = new Form(' | ||
+ | if ($form-> | ||
+ | $values = $form-> | ||
+ | $filter-> | ||
+ | } | ||
+ | $collection = $filter-> | ||
+ | |||
+ | $result = Table:: | ||
+ | </ | ||
+ | |||
+ | ===== Searching results ===== | ||
+ | |||
+ | It is possible to use a form field for searching | ||
+ | |||
+ | ===== Tabulator options ===== | ||
+ | |||
+ | Native tabulator options can be passed to the table from PHP, by using the '' |
table_class.1576964623.txt.gz · Last modified: 2019/12/21 21:43 by sahl