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

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 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