TableJSDataTable.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. class TableJSDataTable {
  3. private $_tbl = '';
  4. private $_cnf = '';
  5. private $_htmlID = '';
  6. private $_dataSource = null;
  7. function __construct($tblName, $tblConf) {
  8. $this->_tbl = $tblName;
  9. $this->_cnf = $tblConf;
  10. $this->_htmlID = $tblName;//uniqid($tblName);
  11. Lib::loadClass('Data_Source');
  12. $this->_dataSource = new Data_Source();
  13. $this->_dataSource->set_table($this->_tbl);
  14. }
  15. function getHtmlID() {
  16. return $this->_htmlID;
  17. }
  18. function render() {
  19. $visible_cols = $this->_cnf->getVisibleFieldList();
  20. $colModel = array();
  21. foreach ($visible_cols as $name) {
  22. $colModel[] = (object)array('display'=>$name, 'name'=>$name, 'width'=>strlen($name) * 5, 'sortable'=>true, 'align'=>'left');
  23. }
  24. $out = '';
  25. //$out .= '<link rel="stylesheet" href="stuff/flexigrid/css/flexigrid.css" type="text/css" />' . "\n";
  26. $out .= '<script src="stuff/jquery.dataTables.min.js"></script>' . "\n";
  27. $out .= '<form id="' . $this->_htmlID . 'Frm" style="display:none">' . "\n";
  28. $out .= 'Value 1 : <input type="text" name="val1" value="" autocomplete="off" /><br />' . "\n";
  29. $out .= 'Value 2 : Is a hidden input with value 3<input type="hidden" name="val2" value="3" /><br />' . "\n";
  30. $out .= 'Value 3 : ' . "\n";
  31. $out .= '<select name="val3">' . "\n";
  32. $out .= '<option value="1">One</option>' . "\n";
  33. $out .= '<option value="2">Two</option>' . "\n";
  34. $out .= '<option value="3">Three</option>' . "\n";
  35. $out .= '<option value="4">Four</option>' . "\n";
  36. $out .= '<option value="5">Five</option>' . "\n";
  37. $out .= '</select><br />' . "\n";
  38. $out .= 'Value 4 : <input type="checkbox" name="val4" id="val4" value="4" /><label for="val4">This will pass a value 4 if checked</label>' . "\n";
  39. $out .= '</p>' . "\n";
  40. $out .= '<p><input type="submit" value="Submit" /></p>' . "\n";
  41. $out .= '</form>';
  42. $out .= '<table id="' . $this->_htmlID . '" cellpadding="0" cellspacing="0" border="1" class="tbl-view">' . "\n";
  43. $out .= '<thead>';
  44. $out .= '<tr>';
  45. foreach ($visible_cols as $name) {
  46. $out .= '<th>' . $name . '</th>';
  47. }
  48. $out .= '</tr>';
  49. $out .= '</thead>';
  50. // $out .= '<tfoot>';
  51. // $out .= '</tfoot>';
  52. $out .= '<tbody>';
  53. $out .= '</tbody>';
  54. $out .= '</table>' . "\n";
  55. $out .= '<script>' . "
  56. $(document).ready(function() {
  57. var oTable = $('#{$this->_htmlID}').dataTable({
  58. 'bProcessing': true,
  59. 'sAjaxSource': 'index-ajax.php?_tbl={$this->_tbl}'
  60. } );
  61. } );
  62. " . '</script>' . "\n";
  63. return $out;
  64. }
  65. }