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:
Não estou conseguindo carregar grids na tela conforme seleção do TCombo.
Alguém consegue me ajudar ?
Segue fonte:
- <?php
- class Cliente extends TPage
- {
- /**
- * Constructor method
- */
- private $form;
- private static $html;
- public function __construct()
- {
- parent::__construct();
- $this->form = new TForm;
- // creates a table
- $table = new TTable;
- $table->width = '100%';
- $this->form->add([$table]);
- // creates a label with the title
- $title = new TLabel('Cliente');
- $title->setFontSize(18);
- $title->setFontFace('Arial');
- $title->setFontColor('red');
- // adds a row to the table
- $row = $table->addRow();
- $title = $row->addCell($title);
- $tipo = new TCombo('tipo_id');
- $items = array();
- $items['1'] = 'Fisico';
- $items['2'] = 'Jurídico';
- $tipo->addItems($items);
- $table->addRowSet($tipo);
- $change_action = new TAction(array($this, 'onTipoCliente'));
- $tipo->setChangeAction($change_action);
- $this->form->setFields([$tipo]);
- //$link1 = new TActionLink('Físico', new TAction(array($this, 'onFisico')), 'green', 10, null, 'fa:search');
- //$link2 = new TActionLink('Jurídico', new TAction(array($this, 'onJuridico')), 'blue', 10, null, 'fa:search');
- //$link1->class = 'btn btn-default';
- //$link2->class = 'btn btn-default';
- $hbox_actions = THBox::pack($table);
- try
- {
- // create the HTML Renderer
- self::$html = new THtmlRenderer('app/view/clienteRender.html');
- // define replacements for the main section
- $replace = array();
- // replace the main section variables
- self::$html->enableSection('main', $replace);
- // Table wrapper (form and HTML)
- $container = new TVBox;
- $container->style = 'width:100%';
- $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($hbox_actions);
- $container->add(self::$html);
- parent::add($container);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- public static function onTipoCliente($param)
- {
- $input_id = $param['_field_id'];
- $tipo_id = $param['_field_value'];
- $input_pieces = explode('_', $input_id);
- $unique_id = end($input_pieces);
- if ($tipo_id == 1)
- {
- Cliente::onFisico();
- }
- if ($tipo_id == 2)
- {
- Cliente::onJuridico();
- }
- }
- public static function onFisico()
- {
- $datagrid = new DataGridClienteFisico;
- $str = get_class($datagrid);
- $replace = array();
- $replace['widget'] = $datagrid;
- $replace['class'] = get_class($datagrid);
- $replace['cliente'] = substr($str, 15);
- // replace the object section variables
- self::$html->enableSection('object', $replace);
- }
- /**
- * Executed when the user clicks at the action2 button
- */
- public static function onJuridico()
- {
- $datagrid = new DataGridClienteJuridico;
- $str = get_class($datagrid);
- $replace = array();
- $replace['widget'] = $datagrid;
- $replace['class'] = get_class($datagrid);
- $replace['cliente'] = substr($str, 15);
- // replace the object section variables
- self::$html->enableSection('object', $replace);
- }
- }
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