EN
tDBSeekButton "customizado" nao traz seleção
Boom dia,
Crieu este tdbseek customizado, mas o select nao esta funcionando, o que estou errando?
Crieu este tdbseek customizado, mas o select nao esta funcionando, o que estou errando?
- <?php
- /**
- * City Seek
- *
- * @version 1.0
- * @package samples
- * @subpackage tutor
- * @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 RacasViewSeek extends TWindow {
- private $form; // form
- private $datagrid; // datagrid
- private $pageNavigation;
- private $loaded;
- /**
- * Class constructor
- * Creates the page, the search form and the listing
- */
- public function __construct() {
- parent::__construct();
- parent::setSize(800, 500);
- parent::setTitle('Pesquisa Raças');
- new TSession;
- // creates the form
- $this->form = new TQuickForm('form_search_racas');
- $this->form->class = 'tform';
- $this->form->setFormTitle('Raças');
- // create the form fields
- $descricao = new TEntry('descricao');
- $descricao->setValue(Tsession::getValue('descricao'));
- $banho = new TEntry('banho');
- $banho->setNumericMask(2, ',', '.', TRUE);
- $banho->setValue(Tsession::getValue('banho'));
- $tosa = new TEntry('tosa');
- $tosa->setNumericMask(2, ',', '.', TRUE);
- $tosa->setValue(Tsession::getValue('tosa'));
- $higienica = new TEntry('higienica');
- $higienica->setNumericMask(2, ',', '.', TRUE);
- $higienica->setValue(Tsession::getValue('higienica'));
- $tesoura = new TEntry('tesoura');
- $tesoura->setNumericMask(2, ',', '.', TRUE);
- $tesoura->setValue(Tsession::getValue('tesoura'));
- // add the form fields
- $this->form->addQuickField('Raça', $descricao, 200);
- // define the form action
- $this->form->addQuickAction('Filtro', new TAction(array($this, 'onSearch')), 'ico_find.png');
- // creates a DataGrid
- $this->datagrid = new TQuickGrid;
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->setHeight(300);
- //$this->datagrid->enablePopover('Raça', 'Raça {descricao}');
- // creates the datagrid columns
- $this->datagrid->addQuickColumn('Id', 'id', 'right', 15);
- $this->datagrid->addQuickColumn('Raça', 'descricao', 'left', 30);
- $this->datagrid->addQuickColumn('Banho', 'banho', 'left', 15);
- $this->datagrid->addQuickColumn('Tosa', 'tosa', 'left', 15);
- $this->datagrid->addQuickColumn('Higienica', 'higienica', 'left', 15);
- $this->datagrid->addQuickColumn('Tesoura', 'tesoura', 'left', 15);
- // creates two datagrid actions
- $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this, 'onSelect')), 'id', 'ico_apply.png');
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // creates a container
- $container = new TVBox;
- $container->style = 'width: 100%';
- $container->add($this->form);
- $container->add($this->datagrid);
- $container->add($this->pageNavigation);
- // add the container inside the page
- parent::add($container);
- }
- /**
- * method onSearch()
- * Register the filter in the session when the user performs a search
- */
- function onSearch() {
- // get the search form data
- $data = $this->form->getData();
- // check if the user has filled the form
- if (isset($data->descricao)) {
- // creates a filter using what the user has typed
- $filter = new TFilter('descricao', 'like', "%{$data->descricao}%");
- // stores the filter in the session
- TSession::setValue('racas_filter', $filter);
- TSession::setValue('racas_descricao', $data->descricao);
- // fill the form with data again
- $this->form->setData($data);
- }
- // redefine the parameters for reload method
- $param = array();
- $param['offset'] = 0;
- $param['first_page'] = 1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL) {
- try {
- // open a transaction with database 'samples'
- TTransaction::open('racas');
- // creates a repository for City
- $repository = new TRepository('Racas');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (!isset($param['order'])) {
- $param['order'] = 'descricao';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('racas_filter')) {
- // add the filter stored in the session to the criteria
- $criteria->add(TSession::getValue('racas_filter'));
- }
- // load the objects according to the criteria
- $racas = $repository->load($criteria);
- $this->datagrid->clear();
- if ($racas) {
- foreach ($racas as $raca) {
- // add the object inside the datagrid
- $this->datagrid->addItem($raca);
- }
- }
- // 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
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Executed when the user chooses the record
- */
- public function onSelect($param) {
- try {
- $key = $param['key'];
- TTransaction::open('Racas');
- // load the active record
- $raca = new Racas($key);
- // closes the transaction
- TTransaction::close();
- $object = new StdClass;
- $object->id = $raca->id;
- $object->descricao = $raca->descricao;
- TForm::sendData('form_seek_racas', $object);
- parent::closeWindow(); // closes the window
- } catch (Exception $e) { // em caso de exceção
- // clear fields
- $object = new StdClass;
- $object->id = '';
- $object->descricao = '';
- TForm::sendData('form_seek_racas', $object);
- // undo pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Shows the page
- */
- function show() {
- // if the datagrid was not loaded yet
- if (!$this->loaded) {
- $this->onReload();
- }
- parent::show();
- }
- }
- ?>
Eduardo, em primeiro lugar habilite os erros do php para garantir que não seja nenhum problema nesse sentido.
A função que envia os dados para o formulário é a TForm::sendData, sendo que o primeiro parâmetro corresponde ao nome do formulário que vai receber as informações. Confirme se o nome do formulário é mesmo "form_seek_racas".
Nataniel Rabaioli:, valeuuuuuuu era isso!!!