Link para download em datagrid? Olá pessoal, fiz algumas buscas aqui no fórum mas não encontrei como eu posso em um datagrid disponibilizar um link para download de um arquivo, alguma dica?...
IV
Link para download em datagrid?  
Fechado
Olá pessoal, fiz algumas buscas aqui no fórum mas não encontrei como eu posso em um datagrid disponibilizar um link para download de um arquivo, alguma dica?

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 (5)


NC

Criando um Action não funciona?
IV

Olá Nilson, não encontrei como usar o "Action" para fazer download do arquivo. Você teria um exemplo?
IV

Conseguir usando o "parent::openFile($file);" mas ao fazer o download e tentar abrir o arquivo é exibida a seguinte mensagem "File type plain text document (text/plain) is not supported"
IF

Olá Iran, o nome do arquivo para download está gravado em uma tabela?
HL

Boa noite!

Estava um pouco afastado aqui do forum, pois estou em uma trabalho com redes.

Porem ja fiz dentro de um projeto o que voce quer, fiz um link dentro de uma datagrid, abaixo segue o codigo, porem claro voce deve ter um tabela com o nome dos arquivos e um diretorio que guarde os arquivos.

Codigo:

 
  1. <?php
 
  1. <?php
  2. /**
  3. * ChamadoList Listing
  4. * @author <your name here>
  5. */
  6. class ChamadoList extends TStandardList
  7. {
  8. protected $form; // registration form
  9. protected $datagrid; // listing
  10. protected $pageNavigation;
  11. /**
  12. * Class constructor
  13. * Creates the page, the form and the listing
  14. */
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. parent::setDatabase('chamado'); // defines the database
  19. parent::setActiveRecord('Chamado'); // defines the active record
  20. parent::setDefaultOrder('id_situacao', 'asc');
  21. // parent::setDefaultOrder('id_prioridade', 'asc');
  22. parent::addFilterField('id', 'like'); // add a filter field
  23. parent::addFilterField('titulo', 'like'); // add a filter field
  24. parent::addFilterField('descricao', 'like'); // add a filter field
  25. parent::addFilterField('data_chamado', 'like'); // add a filter field
  26. parent::addFilterField('id_situacao', 'like'); // add a filter field
  27. parent::addFilterField('id_prioridade', 'like'); // add a filter field
  28. parent::addFilterField('id_categoria', 'like'); // add a filter field
  29. parent::addFilterField('id_unidade', 'like'); // add a filter field
  30. parent::addFilterField('id_sistema', 'like'); // add a filter field
  31. parent::addFilterField('id_segmento', 'like'); // add a filter field
  32. parent::addFilterField('id_usuario', 'like'); // add a filter field
  33. // creates the form, with a table inside
  34. $this->form = new TQuickForm('form_search_Chamado');
  35. $this->form->class = 'tform'; // CSS class
  36. $this->form->setFormTitle('Pesquisar Chamado');
  37. // create the form fields
  38. $id = new TEntry('id');
  39. $titulo = new TEntry('titulo');
  40. $data_chamado = new TDate('data_chamado');
  41. $id_situacao = new TDBCombo('id_situacao', 'chamado', 'situacao', 'id', 'situacao');
  42. $id_prioridade = new TDBCombo('id_prioridade', 'chamado', 'prioridade', 'id', 'prioridade');
  43. $id_categoria = new TDBCombo('id_categoria', 'chamado', 'categoria', 'id', 'categoria');
  44. $id_unidade = new TDBCombo('id_unidade', 'chamado', 'unidade', 'id', 'unidade');
  45. $id_sistema = new TDBCombo ('id_sistema','chamado', 'sistema', 'id', 'sistema');
  46. $id_segmento = new TDBCombo('id_segmento','chamado', 'segmento', 'id', 'segmento');
  47. $id_system_user = new TEntry('id_system_user');
  48. $data_chamado->setMask('dd/mm/yyyy');
  49. // add the fields
  50. $this->form->addQuickField('Título', $titulo, 300);
  51. // $this->form->addQuickField('Data', $data_chamado, 280);
  52. $this->form->addQuickField('Status', $id_situacao, 300);
  53. $this->form->addQuickField('Prioridade', $id_prioridade, 300);
  54. $this->form->addQuickField('Categoria', $id_categoria, 300);
  55. $this->form->addQuickField('Unidade', $id_unidade, 300);
  56. $this->form->addQuickField('Sistema', $id_sistema, 300);
  57. $this->form->addQuickField('Segmento', $id_segmento, 300);
  58. // $this->form->addQuickField('Usuário', $id_system_user, 300);
  59. // keep the form filled during navigation with session data
  60. $this->form->setData( TSession::getValue('Chamado_filter_data') );
  61. // add the search form actions
  62. $this->form->addQuickAction(('Buscar'), new TAction(array($this, 'onSearch')), 'ico_find.png');
  63. $this->form->addQuickAction(('Novo'), new TAction(array('ChamadoForm', 'onEdit')), 'ico_new.png');
  64. // creates a DataGrid
  65. $this->datagrid = new TQuickGrid;
  66. $this->datagrid->setHeight(320);
  67. // creates the datagrid columns
  68. $data_chamado = $this->datagrid->addQuickColumn('Data', 'data_chamado', 'center', 80);
  69. $data_chamado->setTransformer(array($this, 'formatDate'));
  70. $id_usuario = $this->datagrid->addQuickColumn('Usuário', 'usuario_usuario', 'center', 80);
  71. $titulo = $this->datagrid->addQuickColumn('Título', 'titulo', 'left', 360);
  72. $id_unidade = $this->datagrid->addQuickColumn('Unidade', 'unidade_unidade', 'center', 80);
  73. $id_segmento = $this->datagrid->addQuickColumn('Segmento', 'segmento_segmento', 'center', 80);
  74. $id_sistema = $this->datagrid->addQuickColumn('Sistema', 'sistema_sistema', 'center', 80);
  75. $id_categoria = $this->datagrid->addQuickColumn('Categoria', 'categoria_categoria', 'center', 80);
  76. $id_prioridade = $this->datagrid->addQuickColumn('Prioridade', 'prioridade_prioridade', 'center', 80);
  77. $id_situacao = $this->datagrid->addQuickColumn('Status', 'situacao_situacao', 'center', 80);
  78. $this->datagrid->addQuickAction('Visualizar Descrição', new TDataGridAction(array($this, 'onShowDetail')), 'id', 'ico_view.png');
  79. // create the datagrid actions
  80. $edit_action = new TDataGridAction(array('AcompanhamentoFormList', 'onView'));
  81. $this->datagrid->addQuickAction(('Acompanhar Chamado'), $edit_action, 'id', 'ico_add.png');
  82. // create the datagrid model
  83. $this->datagrid->createModel();
  84. // create the page navigation
  85. $this->pageNavigation = new TPageNavigation;
  86. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  87. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  88. // create the page container
  89. // $container = TVBox::pack( $this->form, $this->datagrid, $this->pageNavigation);
  90. $container = new TTable;
  91. $container->style = 'width: auto';
  92. $container->addRow()->addCell(new TXMLBreadCrumb('menu.xml', 'ChamadoList'));
  93. $container->addRow()->addCell($this->form);
  94. $container->addRow()->addCell($this->datagrid);
  95. $container->addRow()->addCell($this->pageNavigation);
  96. parent::add($container);
  97. }
  98. public function onShowDetail( $param ){
  99. // get row position
  100. $pos = $this->datagrid->getRowIndex('id', $param['key']);
  101. // get row by position
  102. $current_row = $this->datagrid->getRow($pos);
  103. TTransaction::open('Chamado');
  104. $chamado = new Chamado($param['key']);
  105. // create a new row
  106. $row = new TTableRow;
  107. $documento = null;
  108. if (!empty($chamado->documento)) {
  109. if (file_exists('./documento_chamado/'.$chamado->id.'/'.$chamado->documento)) {
  110. $documento = '<br><a href="/documento_chamado/'.$chamado->id.'/'.$chamado->documento.'" target="fora">Download</a>';
  111. }
  112. }
  113. $row->addCell('<b>Descrição:</b></br></br></br></br>');
  114. $cell = $row->addCell( $chamado->descricao . '<br>'. $documento);
  115. $cell->colspan = 13;
  116. $cell->style='padding:10px;';
  117. // insert the new row
  118. $this->datagrid->insert($pos +1, $row);
  119. TTransaction::close();
  120. }
  121. public function formatDate($data_chamado, $object)
  122. {
  123. $data_chamado = new DateTime($data_chamado);
  124. return $data_chamado->format('d/m/Y');
  125. }
  126. public function verificaPrioridade($id_prioridade)
  127. {
  128. // if ($id_prioridade == 'ALTA')
  129. // {
  130. //
  131. // return "<span style='color:red'>$id_prioridade</span>";
  132. // }
  133. // if ($id_prioridade == 'MÉDIA')
  134. // {
  135. //
  136. // return "<span style='color:orange'>$id_prioridade</span>";
  137. // }
  138. // if ($id_prioridade == 'BAIXA')
  139. // {
  140. //
  141. // return "<span style='color:green'>$id_prioridade</span>";
  142. // }
  143. }
  144. function show()
  145. {
  146. $this->onReload();
  147. $this->form->clear();
  148. parent::show();
  149. }
  150. }
  151. ?>
</your>