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
- <?php
- /**
- * GrupoList
- *
- * @version 1.0
- * @package erphouse
- * @subpackage control
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- class GrupoList extends TPage
- {
- protected $form; // registration form
- protected $datagrid; // listing
- protected $pageNavigation;
- protected $formgrid;
- protected $deleteButton;
- use Adianti\base\AdiantiStandardListTrait;
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- $this->setDatabase('sys_db'); // defines the database
- $this->setActiveRecord('Grupo'); // defines the active record
- $this->setDefaultOrder('id', 'asc'); // defines the default order
- $this->setLimit(10);
- // $this->setCriteria($criteria) // define a standard filter
- $this->addFilterField('id', '=', 'id'); // filterField, operator, formField
- $this->addFilterField('no_nome', 'like', 'no_nome'); // filterField, operator, formField
- // creates the form
- $this->form = new BootstrapFormBuilder('form_search_Grupo');
- $this->form->setFormTitle('Grupo');
- // create the form fields
- $id = new TEntry('id');
- $nome = new TEntry('no_nome');
- // add the fields
- $this->form->addFields( [ new TLabel('Id') ], [ $id ] );
- $this->form->addFields( [ new TLabel('Nome') ], [ $nome ] );
- // set sizes
- $id->setSize('100%');
- $nome->setSize('100%');
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue(__CLASS__.'_filter_data') );
- // add the search form actions
- $btn = $this->form->addAction(_t('Find'), new TAction([$this, 'onSearch']), 'fa:search');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink(_t('New'), new TAction(['GrupoForm', 'onEdit'], ['register_state' => 'false']), 'fa:plus green');
- // creates a Datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->style = 'width: 100%';
- //$this->datagrid->datatable = 'true';
- // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Id', 'center', '10%');
- $column_nome = new TDataGridColumn('no_nome', 'Nome', 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_nome);
- // creates the datagrid column actions
- $column_id->setAction(new TAction([$this, 'onReload']), ['order' => 'id']);
- $column_nome->setAction(new TAction([$this, 'onReload']), ['order' => 'no_nome']);
- $action1 = new TDataGridAction(['GrupoForm', 'onEdit'], ['id'=>'{id}', 'register_state' => 'false']);
- $action2 = new TDataGridAction([$this, 'onDelete'], ['id'=>'{id}']);
- $this->datagrid->addAction($action1, _t('Edit'), 'far:edit blue');
- $this->datagrid->addAction($action2 ,_t('Delete'), 'far:trash-alt red');
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
- $panel = new TPanelGroup('', 'white');
- $panel->add($this->datagrid);
- $panel->addFooter($this->pageNavigation);
- // header actions
- $dropdown = new TDropDown(_t('Export'), 'fa:list');
- $dropdown->setPullSide('right');
- $dropdown->setButtonClass('btn btn-info waves-effect dropdown-toggle');
- $dropdown->addAction( _t('Save as CSV'), new TAction([$this, 'onExportCSV'], ['register_state' => 'false', 'static'=>'1']), 'fa:table blue' );
- $dropdown->addAction( _t('Save as PDF'), new TAction([$this, 'onExportPDF'], ['register_state' => 'false', 'static'=>'1']), 'far:file-pdf red' );
- $panel->addHeaderWidget( $dropdown );
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 100%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- $container->add($panel);
- parent::add($container);
- }
- }
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".
já resolvir, o problema era forma que que modelei o banco de dados