Datagrid Detail Não consigo pegar o index da linha ao executar: Criação da grid: ...
T
Datagrid Detail  
Não consigo pegar o index da linha ao executar:
 
  1. <?php
  2. $pos = $this->grid_tributos->getRowIndex('detail', $param['chave']);
  3. ?>


Criação da grid:
 
  1. <?php
  2. $this->grid_tributos = new TQuickGrid;
  3. $this->grid_tributos->class = "tdatagrid_table customized-table";
  4. $this->grid_tributos->style = 'width: 100%';
  5. $this->grid_tributos->setHeight( 250 );
  6. $this->grid_tributos->addQuickColumn('', 'edit', 'left', '5%');
  7. $this->grid_tributos->addQuickColumn('', 'detail', 'left', '5%');
  8. $this->grid_tributos->addQuickColumn('', 'delete', 'left', '5%');
  9. $this->grid_tributos->addQuickColumn('Tipo Imposto', 'tipoImposto', 'center', '30%');
  10. $this->grid_tributos->addQuickColumn('Alíquota %', 'aliquotaImposto', 'center', '30%');
  11. $this->grid_tributos->addQuickColumn('Estado', 'estado', 'center', '30%');
  12. $this->grid_tributos->createModel();
  13. $scroll = new TScroll();
  14. $scroll->setSize('100%', '250');
  15. $scroll->style = 'width: 100%';
  16. $scroll->add($this->grid_tributos);
  17. ?>


Metodo onReload:

 
  1. <?php
  2. function onReloadTributo($param = NULL)
  3. {
  4. $tributos = TSession::getValue('tributos_produto');
  5. $this->grid_tributos->clear();
  6. if (isset($tributos))
  7. {
  8. $cont = 1;
  9. foreach($tributos as $item)
  10. {
  11. $item_name = 'cont_' . $cont++;
  12. $action_edi = new TAction(array($this, 'onEditTributo'));
  13. $action_edi->setParameter('chave', $item['cad_estado_id'].$item['tipoImposto']);
  14. $button_edi = new TButton('edit_tributo'.$cont);
  15. $button_edi->setAction( $action_edi, '' );
  16. $button_edi->setImage('fa:edit blue fa-lg');
  17. $button_edi->style = 'width:13px; padding-left:6px; border-style: none; background: transparent;';
  18. $action_det = new TAction(array($this, 'onDetailTributo'));
  19. $action_det->setParameter('chave', $item['cad_estado_id'].$item['tipoImposto']);
  20. $button_det = new TButton('detail_tributo'.$cont);
  21. $button_det->setAction( $action_det, '' );
  22. $button_det->setImage('fa:edit red fa-lg');
  23. $button_det->style = 'width:13px; padding-left:6px; border-style: none; background: transparent;';
  24. $action_del = new TAction(array($this, 'onDeleteTributo'));
  25. $action_del->setParameter('chave', $item['cad_estado_id'].$item['tipoImposto']);
  26. $button_del = new TButton('delete_tributo'.$cont);
  27. $button_del->setAction( $action_del, '' );
  28. $button_del->setImage('fa:trash-o red fa-lg');
  29. $button_del->style = 'width:13px; padding-left:6px; border-style: none; background: transparent;';
  30. $tributo = new StdClass;
  31. $tributo->edit = $button_edi;
  32. $tributo->detail = $button_det;
  33. $tributo->delete = $button_del;
  34. $tributo->tipoImposto = $item['tipoImposto'];
  35. $tributo->aliquotaImposto = $item['aliquotaImposto'];
  36. $tributo->estado = $item['estado'];
  37. $this->formFields[ $item_name.'_edit' ] = $tributo->edit;
  38. $this->formFields[ $item_name.'_detail' ] = $tributo->detail;
  39. $this->formFields[ $item_name.'_delete' ] = $tributo->delete;
  40. $this->grid_tributos->addItem($tributo);
  41. }
  42. $this->form->setFields( $this->formFields );
  43. }
  44. }
  45. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


NR

Veja a função getRowIndex:
 
  1. <?php
  2. /**
  3. * Find the row index by object attribute
  4. * @param $attribute Object attribute
  5. * @param $value Object value
  6. */
  7. public function getRowIndex($attribute, $value)
  8. {
  9. foreach ($this->objects as $pos => $object)
  10. {
  11. if ($object->$attribute == $value)
  12. {
  13. return $pos;
  14. }
  15. }
  16. return NULL;
  17. }
  18. ?>

Ela compara o valor do atributo ($attribute) de cada item da grid com o valor fixo do segundo parâmetro da função($value). Se forem iguais retorna o índice. Acontece que o atributo $tributo->detail é um TButton, por isso nenhum resultado é encontrado. Para retornar o índice corretamente o valor de $object->atributo deve ser igual a $param['chave']

Use outro atributo para identificar o item.
T

Consegui Nataniel, obrigado!
Outra duvida, não existe nenhuma forma de utilizar o collspan com o datatable mesmo não?