User Tools

Site Tools


table_class

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
table_class [2020/08/07 12:34] sahltable_class [2021/03/18 21:20] (current) sahl
Line 18: Line 18:
 ===== Datarecord convenience ===== ===== Datarecord convenience =====
  
-The easiest way to work with [[Datarecord class|Datarecord]] is using the [[DatarecordEditComplex class]], but to build custom way to interact with data recordsit can still be done like this:+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 dataand adds the options to create, edit and delete such data. 
 + 
 +Stepping down notch is the ''Table::getTableFromClass($table_id, $class_name)'' which get a table configured for displaying all data from the class given and which is ready to render. See below on how to filter this data further. 
 + 
 +The most manual way to get data from a Datarecord is as followswhere you also need to construct and provide your own data url.
  
 <code php index.php> <code php index.php>
Line 29: Line 33:
 <code php data.php> <code php data.php>
 // Get all data // Get all data
-$filter = new Platform\Filter(DATARECORD CLASS NAME);+$filter = new Filter(DATARECORD CLASS NAME);
 $collection = $filter->execute(); $collection = $filter->execute();
  
Line 38: Line 42:
 </code> </code>
  
 +===== 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->addCondition(new ConditionMatch('fieldname', 'value'));
 +
 +$table->setFilter($filter);
 +</code>
 +
 +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::getFilterFromJSON($_POST['filter']);
 +</code>
 +
 +which will yield the same filter as passed into the table.
 +
 +===== Actionbuttons =====
 +
 +As a convenience one can easily add an //actionbutton// on each row. An actionbutton is an icon from Fontawesome, which will trigger a javascript function with the ID of the row as the parameter.
 +
 +<code>
 +$table->addActionButton('fa-envelope-open-o', 'mailme');
 +</code>
 +
 +The following will add an icon of an open envelope on each row, and each time it is clicked, the javascript function ''mailme(id)'' will be called, where id is the id of the data row.
 +
 +===== Selecting items =====
 +
 +In order to display checkboxes next to each data row, one can call the ''showSelector()'' function on the table.
 +
 +<code php>
 +$table->showSelector();
 +</code>
 +
 +This will render checkboxes next to each table row.
 +
 +These checked values can be retrieved from javascript using the ''getSelectedTableIds(tableid)'' function, where tableid is the HTML id of the table.
 +
 +===== Providing a search form =====
 +
 +It is possible to integrate a search form into the table, if one also writes the data url. A form can easily be added to the table by doing this:
 +
 +<code php>
 +$form = new Form('searchform', 'search.form');
 +
 +$table->setDataURL('data.php');
 +$table->attachForm($form);
 +</code>
 +
 +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('searchform', 'search.form');
 +if ($form->isSubmitted()) {
 +  $values = $form->getValues();
 +  $filter->addCondition(new ConditionLike('field_to_search', $values['value_to_find']));
 +}
 +$collection = $filter->execute();
 +
 +$result = Table::getDataFromCollection($collection);
 +</code>
 +
 +===== Searching results =====
 +
 +It is possible to use a form field for searching through the results already displayed in the table. In order to do this attach the form field using ''addTabulatorOption('filter_field', 'ID_OF_FORM_FIELD')''.
 +
 +===== Tabulator options =====
  
 +Native tabulator options can be passed to the table from PHP, by using the ''addTabulatorOption($option, $value)'' function.
table_class.1596803651.txt.gz · Last modified: 2020/08/07 12:34 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki