Structures_DataGrid
[ class tree: Structures_DataGrid ] [ index: Structures_DataGrid ] [ all elements ]

Source for file checkablehtmltable.php

Documentation is available at checkablehtmltable.php

  1. <?php
  2. require_once 'HTML/QuickForm.php';
  3. require_once 'HTML/QuickForm/Renderer/QuickHtml.php';
  4. require_once 'Structures/DataGrid.php';
  5.  
  6. // prepare the form and the QuickHtml renderer
  7. $form =new HTML_QuickForm();
  8. $renderer =new HTML_QuickForm_Renderer_QuickHtml();
  9.  
  10. // add action selectbox and submit button to the form
  11. $form->addElement('select''action''choose',
  12.                   array('delete' => 'Delete',
  13.                         'move'   => 'Move to archive'));
  14. $form->addElement('submit''submit''Save');
  15.  
  16. // prepare the DataGrid
  17. $dg =new Structures_DataGrid();
  18. if (PEAR::isError($dg)) {
  19.    die($dg->getMessage('<br />' $dg->getDebugInfo());
  20. }
  21.  
  22. // bind some data (e.g. via a SQL query and MDB2)
  23. $error $dg->bind('SELECT * FROM news',
  24.                    array('dsn' => 'mysql://user:password@server/database'));
  25. if (PEAR::isError($error)) {
  26.    die($error->getMessage('<br />' $error->getDebugInfo());
  27. }
  28.  
  29. // the renderer adds an auto-generated column for the checkbox by default;
  30. // it is also possible to add a column yourself, for example like in the
  31. // following four lines:
  32. $column = new Structures_DataGrid_Column('checkboxes''idList'null,
  33.                                          array('width' => '10'));
  34. $dg->addColumn($column);
  35. $dg->generateColumns();
  36.  
  37. $rendererOptions = array('form'         => $form,
  38.                          'formRenderer' => $renderer,
  39.                          'inputName'    => 'idList',
  40.                          'primaryKey'   => 'id'
  41.                         );
  42.  
  43. // use a template string for the form
  44. $tpl '';
  45.  
  46. // generate the HTML table and add it to the template string
  47. $tpl .= $dg->getOutput('CheckableHTMLTable'$rendererOptions);
  48. if (PEAR::isError($tpl)) {
  49.    die($tpl->getMessage('<br />' $tpl->getDebugInfo());
  50. }
  51.  
  52. // add the HTML code of the action selectbox and the submit button to the
  53. // template string
  54. $tpl .= $renderer->elementToHtml('action');
  55. $tpl .= $renderer->elementToHtml('submit');
  56.  
  57. // we're now ready to output the form (toHtml() adds the <form> / </form>
  58. // pair to the template)
  59. echo $renderer->toHtml($tpl);
  60.  
  61. // if the form was submitted and the data is valid, show the submitted data
  62. if ($form->isSubmitted(&& $form->validate()) {
  63.     var_dump($form->getSubmitValues());
  64. }
  65. ?>

Documentation generated on Mon, 11 Mar 2019 15:47:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.