Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Formulário de Edição não sendo vinculado ao id específico banco de dados mysql, não consigo fazer a edição buscando pelo id na datagrid ...
HL
Formulário de Edição não sendo vinculado ao id específico  
banco de dados mysql, não consigo fazer a edição buscando pelo id na datagrid

  1. <?php
  2. /**
  3.  * GrupoList
  4.  *
  5.  * @version    1.0
  6.  * @package    erphouse
  7.  * @subpackage control
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class GrupoList extends TPage
  13. {
  14.     protected $form;     // registration form
  15.     protected $datagrid// listing
  16.     protected $pageNavigation;
  17.     protected $formgrid;
  18.     protected $deleteButton;
  19.     
  20.     use Adianti\base\AdiantiStandardListTrait;
  21.     
  22.     /**
  23.      * Page constructor
  24.      */
  25.     public function __construct()
  26.     {
  27.         parent::__construct();
  28.         
  29.         $this->setDatabase('sys_db');            // defines the database
  30.         $this->setActiveRecord('Grupo');   // defines the active record
  31.         $this->setDefaultOrder('id''asc');         // defines the default order
  32.         $this->setLimit(10);
  33.         // $this->setCriteria($criteria) // define a standard filter
  34.         $this->addFilterField('id''=''id'); // filterField, operator, formField
  35.         $this->addFilterField('no_nome''like''no_nome'); // filterField, operator, formField
  36.         
  37.         // creates the form
  38.         $this->form = new BootstrapFormBuilder('form_search_Grupo');
  39.         $this->form->setFormTitle('Grupo');
  40.         
  41.         // create the form fields
  42.         $id = new TEntry('id');
  43.         $nome = new TEntry('no_nome');
  44.         // add the fields
  45.         $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
  46.         $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
  47.         // set sizes
  48.         $id->setSize('100%');
  49.         $nome->setSize('100%');
  50.         
  51.         // keep the form filled during navigation with session data
  52.         $this->form->setDataTSession::getValue(__CLASS__.'_filter_data') );
  53.         
  54.         // add the search form actions
  55.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  56.         $btn->class 'btn btn-sm btn-primary';
  57.         $this->form->addActionLink(_t('New'), new TAction(['GrupoForm''onEdit'], ['register_state' => 'false']), 'fa:plus green');
  58.         
  59.         // creates a Datagrid
  60.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  61.         $this->datagrid->style 'width: 100%';
  62.         //$this->datagrid->datatable = 'true';
  63.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  64.         
  65.         // creates the datagrid columns
  66.         $column_id = new TDataGridColumn('id''Id''center''10%');
  67.         $column_nome = new TDataGridColumn('no_nome''Nome''left');
  68.         // add the columns to the DataGrid
  69.         $this->datagrid->addColumn($column_id);
  70.         $this->datagrid->addColumn($column_nome);
  71.         // creates the datagrid column actions
  72.         $column_id->setAction(new TAction([$this'onReload']), ['order' => 'id']);
  73.         $column_nome->setAction(new TAction([$this'onReload']), ['order' => 'no_nome']);
  74.         
  75.         $action1 = new TDataGridAction(['GrupoForm''onEdit'], ['id'=>'{id}''register_state' => 'false']);
  76.         $action2 = new TDataGridAction([$this'onDelete'], ['id'=>'{id}']);
  77.         
  78.         $this->datagrid->addAction($action1_t('Edit'),   'far:edit blue');
  79.         $this->datagrid->addAction($action2 ,_t('Delete'), 'far:trash-alt red');
  80.         
  81.         // create the datagrid model
  82.         $this->datagrid->createModel();
  83.         
  84.         // creates the page navigation
  85.         $this->pageNavigation = new TPageNavigation;
  86.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  87.         
  88.         $panel = new TPanelGroup('''white');
  89.         $panel->add($this->datagrid);
  90.         $panel->addFooter($this->pageNavigation);
  91.         
  92.         // header actions
  93.         $dropdown = new TDropDown(_t('Export'), 'fa:list');
  94.         $dropdown->setPullSide('right');
  95.         $dropdown->setButtonClass('btn btn-info waves-effect dropdown-toggle');
  96.         $dropdown->addAction_t('Save as CSV'), new TAction([$this'onExportCSV'], ['register_state' => 'false''static'=>'1']), 'fa:table blue' );
  97.         $dropdown->addAction_t('Save as PDF'), new TAction([$this'onExportPDF'], ['register_state' => 'false''static'=>'1']), 'far:file-pdf red' );
  98.         $panel->addHeaderWidget$dropdown );
  99.         
  100.         // vertical box container
  101.         $container = new TVBox;
  102.         $container->style 'width: 100%';
  103.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  104.         $container->add($this->form);
  105.         $container->add($panel);
  106.         
  107.         parent::add($container);
  108.     }
  109. }

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 (2)


NR

Se entendi, ao clicar para editar um item da grid o formulário não carrega as informações. É isso?

Normalmente a função onEdit utiliza o parâmetro "key" para identificar o id do registro. Aparentemente você está informando somente o parâmetro "id".
HL

já resolvir, o problema era forma que que modelei o banco de dados