WR
Reload DataGrid
Boa tarde!!
Pessoal , eu sobrescrevi o método onSave , mas não estou conseguindo recarregar o dataGrid após o onSave;
Pessoal , eu sobrescrevi o método onSave , mas não estou conseguindo recarregar o dataGrid após o onSave;
- <?php
- /**
- * Overloaded method onSave()
- * Executed whenever the user clicks at the save button
- */
- public function onSave($param)
- {
- try
- {
- TTransaction::open('sirvo');
- // form validations
- $this->form->validate();
- // get form data
- $data = $this->form->getData();
- // store product
- $object = new Veiculo;
- $object->fromArray( (array) $data);
- $object->store();
- // copy file to target folder
- $this->saveFile($object, $data, 'foto_path', 'app/images');
- // send id back to the form
- $data->id = $object->id;
- $this->form->setData($data);
- $this->onReload(); // reload the items
- TTransaction::close();
- new TMessage('info', AdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e)
- {
- $this->form->setData($this->form->getData());
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database
- TTransaction::open('sirvo');
- $order = isset($param['order']) ? $param['order'] : 'id';
- // load the objects according to criteria
- $veiculos = Veiculo::orderBy($order)->load();
- $this->datagrid->clear();
- if ($veiculos)
- {
- // iterate the collection of active records
- foreach ($veiculos as $veiculo)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($veiculo);
- }
- }
- // 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();
- }
- }
- ?>
Não sei qual a mensagem de erro, mas eu mudaria o $this->onReload() para depois do TTransaction::close() em onSave.
Tente fazer isso.
Olá Marcelo Gomes, na verdade não dá erro nenhum, só não recarrega o grid.
Mas fiz o que você sugeriu e funcionou de boa. A gente olha umas trezentas vezes e não vê o erro!
Por isso é sempre bom alguém de fora dar uma olhadinha!!
Obrigado pela ajuda!!
Abraços
Não por isso. São detalhes, você estava chamando o onReload dentro de uma transação em andamento. E dentro do onReload, você abria outra.....
Estamos aqui pra ajudar!
Abraços