Dificuldade em carregar grid em um THmlRender Olá, pessoal Não estou conseguindo carregar grids na tela conforme seleção do TCombo. Alguém consegue me ajudar ? Segue fonte: ...
RB
Dificuldade em carregar grid em um THmlRender  
Olá, pessoal

Não estou conseguindo carregar grids na tela conforme seleção do TCombo.

Alguém consegue me ajudar ?

Segue fonte:
 
  1. <?php
  2. class Cliente extends TPage
  3. {
  4. /**
  5. * Constructor method
  6. */
  7. private $form;
  8. private static $html;
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. $this->form = new TForm;
  13. // creates a table
  14. $table = new TTable;
  15. $table->width = '100%';
  16. $this->form->add([$table]);
  17. // creates a label with the title
  18. $title = new TLabel('Cliente');
  19. $title->setFontSize(18);
  20. $title->setFontFace('Arial');
  21. $title->setFontColor('red');
  22. // adds a row to the table
  23. $row = $table->addRow();
  24. $title = $row->addCell($title);
  25. $tipo = new TCombo('tipo_id');
  26. $items = array();
  27. $items['1'] = 'Fisico';
  28. $items['2'] = 'Jurídico';
  29. $tipo->addItems($items);
  30. $table->addRowSet($tipo);
  31. $change_action = new TAction(array($this, 'onTipoCliente'));
  32. $tipo->setChangeAction($change_action);
  33. $this->form->setFields([$tipo]);
  34. //$link1 = new TActionLink('Físico', new TAction(array($this, 'onFisico')), 'green', 10, null, 'fa:search');
  35. //$link2 = new TActionLink('Jurídico', new TAction(array($this, 'onJuridico')), 'blue', 10, null, 'fa:search');
  36. //$link1->class = 'btn btn-default';
  37. //$link2->class = 'btn btn-default';
  38. $hbox_actions = THBox::pack($table);
  39. try
  40. {
  41. // create the HTML Renderer
  42. self::$html = new THtmlRenderer('app/view/clienteRender.html');
  43. // define replacements for the main section
  44. $replace = array();
  45. // replace the main section variables
  46. self::$html->enableSection('main', $replace);
  47. // Table wrapper (form and HTML)
  48. $container = new TVBox;
  49. $container->style = 'width:100%';
  50. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  51. $container->add($hbox_actions);
  52. $container->add(self::$html);
  53. parent::add($container);
  54. }
  55. catch (Exception $e)
  56. {
  57. new TMessage('error', $e->getMessage());
  58. }
  59. }
  60. public static function onTipoCliente($param)
  61. {
  62. $input_id = $param['_field_id'];
  63. $tipo_id = $param['_field_value'];
  64. $input_pieces = explode('_', $input_id);
  65. $unique_id = end($input_pieces);
  66. if ($tipo_id == 1)
  67. {
  68. Cliente::onFisico();
  69. }
  70. if ($tipo_id == 2)
  71. {
  72. Cliente::onJuridico();
  73. }
  74. }
  75. public static function onFisico()
  76. {
  77. $datagrid = new DataGridClienteFisico;
  78. $str = get_class($datagrid);
  79. $replace = array();
  80. $replace['widget'] = $datagrid;
  81. $replace['class'] = get_class($datagrid);
  82. $replace['cliente'] = substr($str, 15);
  83. // replace the object section variables
  84. self::$html->enableSection('object', $replace);
  85. }
  86. /**
  87. * Executed when the user clicks at the action2 button
  88. */
  89. public static function onJuridico()
  90. {
  91. $datagrid = new DataGridClienteJuridico;
  92. $str = get_class($datagrid);
  93. $replace = array();
  94. $replace['widget'] = $datagrid;
  95. $replace['class'] = get_class($datagrid);
  96. $replace['cliente'] = substr($str, 15);
  97. // replace the object section variables
  98. self::$html->enableSection('object', $replace);
  99. }
  100. }

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (1)


NR

O erro diz que self::$html é null. Isso acontece porque você inicializa essa variável no construtor da classe mas o construtor não é chamado ao utilizar funções estáticas.

Para adicionar/substituir linhas de uma grid de forma estática você pode usar a função "TDataGrid::replaceRowById('products_list', $uniqid, $row)". Veja no exemplo abaixo:
https://adianti.com.br/framework_files/tutor/index.php?class=SaleForm