RB
Dificuldade em manter botões acima da grid
Olá Pessoal,
Criei uma pagina com template html, e nesta página alterno entre grid fisico e juridico, porém ao navegar entre as paginações das grids estou tendo dificuldades em manter os botões de alternância e os titulos .na grid.
Alguém pode me ajudar ?
Segue código abaixo :
<!--[main]-->
<link href="app/resources/styles.css" rel="stylesheet" type="text/css" media="screen" />
<table class="customform" style="width: 100%">
<!--[object]-->
<tr>
<td colspan="2">{$widget}</td>
</tr>
<!--[/object]-->
</table>
<!--[/main]-->
Classe cliente
Estrutura grid
Criei uma pagina com template html, e nesta página alterno entre grid fisico e juridico, porém ao navegar entre as paginações das grids estou tendo dificuldades em manter os botões de alternância e os titulos .na grid.
Alguém pode me ajudar ?
Segue código abaixo :
<!--[main]-->
<link href="app/resources/styles.css" rel="stylesheet" type="text/css" media="screen" />
<table class="customform" style="width: 100%">
<!--[object]-->
<tr>
<td colspan="2">{$widget}</td>
</tr>
<!--[/object]-->
</table>
<!--[/main]-->
Classe cliente
- <?php
- class Cliente extends TPage
- {
- /**
- * Constructor method
- */
- protected $hbox_actions;
- protected $container;
- public function __construct()
- {
- parent::__construct();
- $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';
- $this->hbox_actions = THBox::pack($link1,$link2);
- try
- {
- // create the HTML Renderer
- $this->html = new THtmlRenderer('app/view/clienteRender.html');
- $this->onFisico();
- // define replacements for the main section
- $replace = array();
- // replace the main section variables
- $this->html->enableSection('main', $replace);
- // Table wrapper (form and HTML)
- $this->container = new TVBox;
- $this->container->style = 'width:100%';
- $this->container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $this->container->add($this->hbox_actions);
- $this->container->add($this->html);
- parent::add($this->container);
- }
- catch (Exception $e)
- {
- new TMessage('error', $e->getMessage());
- }
- }
- /**
- * Executed when the user clicks at the action1 button
- */
- public 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
- $this->html->enableSection('object', $replace);
- }
- /**
- * Executed when the user clicks at the action2 button
- */
- public 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
- $this->html->enableSection('object', $replace);
- }
- }
- ?>
Estrutura grid
- <?php
- class DataGridClienteJuridico extends TPage
- {
- private $datagrid, $pageNavigation, $loaded;
- private static $db = 'db';
- public function __construct()
- {
- parent::__construct();
- // creates one datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->width = '100%';
- // add the columns
- $this->datagrid->addColumn(new TDataGridColumn('pessoa_id','#','center',''));
- $cnpj = $this->datagrid->addColumn(new TDataGridColumn('pessoa->juridica->cnpj','CNPJ','left',''));
- $data_cadastro = $this->datagrid->addColumn(new TDataGridColumn('pessoa->juridica->razao_social','Razão Social','left',''));
- $nome_fantasia = $this->datagrid->addColumn(new TDataGridColumn('pessoa->juridica->nome_fantasia','Nome Fantasia','left',''));
- $unidade = $this->datagrid->addColumn(new TDataGridColumn('pessoa->juridica->tipo->nome',_t('Unit'),'left',''));
- $atividade_principal = $this->datagrid->addColumn(new TDataGridColumn('pessoa->juridica->atividade_principal','Atividade Principal','left',''));
- $email = $this->datagrid->addColumn(new TDataGridColumn('pessoa->juridica->email','Email','left',''));
- $cidade = $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->estado->nome','Cidade','left',''));
- $uf = $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->estado->uf','UF','left',''));
- $editar = $this->datagrid->addColumn(new TDataGridColumn('editar','','center'));
- $deletar = $this->datagrid->addColumn(new TDataGridColumn('deletar','','center'));
- $data_cadastro->enableAutoHide(500);
- $nome_fantasia->enableAutoHide(600);
- //$unidade->enableAutoHide(700);
- $atividade_principal->enableAutoHide(800);
- $email->enableAutoHide(900);
- $uf->enableAutoHide(1000);
- $cidade->enableAutoHide(1000);
- $uf->setDataProperty('style','font-weight: bold');
- // creates the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- $this->pageNavigation->enableCounters();
- // search box
- $input_search = new TEntry('input_search');
- $input_search->placeholder = _t('Search');
- $input_search->setSize('100%');
- // enable fuse search by column name
- $this->datagrid->enableSearch($input_search,'pessoa_id,pessoa->juridica->cnpj,pessoa->juridica->razao_social,pessoa->juridica->atividade_principal,pessoa->juridica->email,pessoa_endereco->endereco->estado->nome,pessoa_endereco->endereco->estado->uf');
- $panel = new TPanelGroup('{$cliente}');
- $panel->addHeaderWidget($input_search);
- $panel->add($this->datagrid)->style = 'overflow-x:auto';
- $panel->addFooter($this->pageNavigation);
- $link = new TActionLink('Incluir', new TAction(array('JuridicaForm', 'onClear')), 'white', 12, null, 'fa:plus-circle');
- $link->class = 'btn btn-default';
- $link->style .= ';margin: 10px 45% 0 45%;padding:3px 10px 5px 10px;heigth:25px;background:#112a47;color:#fff;text-shadow: 1px 1px #333;';
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- //$vbox->add(new TXMLBreadCrumb('menu.xml',__CLASS__));
- $vbox->add($panel);
- $vbox->add($link);
- parent::add($vbox);
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database self::$db
- TTransaction::open(self::$db);
- // creates a repository for PessoaVinculo
- $repository = new TRepository('PessoaVinculo');
- $limit = 3;
- // creates a criteria
- $criteria = new TCriteria;$criteria->add(new TFilter('tipo_pessoa_id','=', 2));
- //$criteria->add(new TFilter('tipo_vinculo_id','=', 2));
- //$criteria->add(new TFilter('system_unit_id','=', TSession::getValue('userunitid')));
- $criteria->add(new TFilter('situacao_id', '=', 1));
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'pessoa_id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- // load the objects according to criteria
- $objects = $repository->load($criteria);
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- //cria os botões de ação e adiciona a datagrid
- $edit = new TElement('i');
- $edit->class="fa fa-search blue";
- $action = new TAction(['JuridicaForm','onEdit'],['pessoa_id'=>"$object->pessoa_id"]);
- $action->setParameter('key',$object->pessoa_id);
- $object->editar = $edit;
- $a = new TActionLink($edit, $action);
- $a->class = 'btn_transparent';
- $del = new TElement('i');
- $del->class ="fa fa-trash-alt red";
- $action1 = new TAction(array($this, 'onDelete'));
- $action1->setParameter('key',$object->pessoa_id);
- $object->deletar = $del;
- $b = new TActionLink($del, $action1);
- $b->class = 'btn_transparent';
- $object->editar = $a;
- $object->deletar = $b;
- $object->pessoa->juridica->cnpj = FuncoesUteis::formataString('cnpj',$object->pessoa->juridica->cnpj);
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count = $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Executed when the user clicks at the view button
- */
- public static function onView($param)
- {
- // get the parameter and shows the message
- $code = $param['pessoa_id'];
- $name = $param['pessoa->juridica->nome'];
- new TMessage('info', "The code is: <b>$code</b> <br> The name is : <b>$name</b>");
- }
- /**
- * Ask before deletion
- */
- public static function onDelete($param)
- {
- // define the delete action
- $action = new TAction(array(__CLASS__, 'Delete'));
- $action->setParameters($param); // pass the key parameter ahead
- // shows a dialog to the user
- new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * Delete a record
- */
- public static function Delete($param)
- {
- try
- {
- $key = $param['key']; // get the parameter $key
- $system_unit_id = TSession::getValue('userunitid');
- TTransaction::open(self::$db); // open a transaction with database
- $cliente = PessoaVinculo::where('pessoa_id','=', $key)
- ->where('system_unit_id','=',$system_unit_id)
- ->set('situacao_id', 10)
- ->update();
- TTransaction::close(); // close the transaction
- $pos_action = new TAction([__CLASS__, 'onReload']);
- new TMessage('info', AdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * shows the page
- */
- function show()
- {
- $this->onReload();
- parent::show();
- }
- }
Bom dia.
Costumo criar um form e adicionar pelo menos um THidden e os botões que preciso.
Ao incluir no container, no final do código do constructor, tenha a atenção de colocar os componentes (form e grid) na ordem em que deseja que apareçam.
Se o espaço referente ao form ficar ocupando mais espaço do que deveria: css nele.
Contudo, creio ter visto um exemplo desse mesmo estilo que necessita no Tutor. Dê uma olhada lá.
Espero ter ajudado.
Quem adiciona os botões na parte superior é a classe Cliente, mas ao usar a paginação é chamada diretamente a classe da grid, desse modo a tela é recarregada somente com a renderização da grid.
Você pode usar a função setTargetContainer pra fazer com que somente uma parte da tela seja recarregada. Veja o exemplo do tutor:
adianti.com.br/framework_files/tutor/index.php?class=InboxView