Responsive datatable and buttons in the last column

Responsive datatable and buttons in the last column

jwestjwest Posts: 8Questions: 4Answers: 0

Hi, I have datatable with buttons(delete/edit) in the last column. I am using responsive table.

When the screen is done small, a button appears in the first column to show the details and my buttons(delete/edit) go to a child row.

When the screen is bigger. I have used the next code in JS to handle the edit/delete buttons:
/ok to big screen/

var btnDel=$('#mytable tbody').on( 'click', 'button.eliminar', function () {
var data=table.row($(this).parents('tr')).data();
var pront=data.pront; // this is my data row id
var row = $(this).closest("tr").get(0); //here is the row containing the clicked button
..other staff
});

Now, when the screen is smaller(with responsive table), this is not working.

How could I do it work to small screen?

Here is the source code when the child is showing:

Pront Nome Endereço Bairro Cidade UF Telefone Convênio CPF E-Mail Opções
Pront Nome Endereço Bairro Cidade UF Telefone Convênio CPF E-Mail Opções
21 JACENI FERRARI ALENCAR R ARAGUAIA PARQUE CHUNO DUQUE DE CAXIAS RJ 35637685 BRADESCO (B) 02570293709 jaceni@ig.com.br
  • UF RJ
  • Telefone 35637685
  • Convênio BRADESCO (B)
  • CPF 02570293709
  • E-Mail jaceni@ig.com.br
  • Opções
23 PEDRO HENRIQUES MARTINS SOUZA rua 18 de outubro 241 101 tijuca RIO DE JANEIRO RJ CASSI

Answers

  • jwestjwest Posts: 8Questions: 4Answers: 0

    <table id="mytable" class="table table-striped table-bordered nowrap dataTable dtr-inline collapsed" cellspacing="0" width="100%" style="display: table; width: 100%;" role="grid" aria-describedby="mytable_info"> <thead> <tr role="row"> <th class="sorting_asc" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 37px;" aria-sort="ascending" aria-label="Pront: Ordenar colunas de forma descendente">Pront</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 272px;" aria-label="Nome: Ordenar colunas de forma ascendente">Nome</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 231px;" aria-label="Endereço: Ordenar colunas de forma ascendente">Endereço</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 133px;" aria-label="Bairro: Ordenar colunas de forma ascendente">Bairro</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 101px;" aria-label="Cidade: Ordenar colunas de forma ascendente">Cidade</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 0px; display: none;" aria-label="UF: Ordenar colunas de forma ascendente">UF</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 0px; display: none;" aria-label="Telefone: Ordenar colunas de forma ascendente">Telefone</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 0px; display: none;" aria-label="Convênio: Ordenar colunas de forma ascendente">Convênio</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 0px; display: none;" aria-label="CPF: Ordenar colunas de forma ascendente">CPF</th> <th class="sorting" tabindex="0" aria-controls="mytable" rowspan="1" colspan="1" style="width: 0px; display: none;" aria-label="E-Mail: Ordenar colunas de forma ascendente">E-Mail</th> <th class="center sorting_disabled" rowspan="1" colspan="1" style="width: 0px; display: none;" aria-label="Opções">Opções</th> </tr> </thead> <tfoot> <tr> <th rowspan="1" colspan="1">Pront</th> <th rowspan="1" colspan="1">Nome</th> <th rowspan="1" colspan="1">Endereço</th> <th rowspan="1" colspan="1">Bairro</th> <th rowspan="1" colspan="1">Cidade</th> <th rowspan="1" colspan="1" style="display: none;">UF</th> <th rowspan="1" colspan="1" style="display: none;">Telefone</th> <th rowspan="1" colspan="1" style="display: none;">Convênio</th> <th rowspan="1" colspan="1" style="display: none;">CPF</th> <th rowspan="1" colspan="1" style="display: none;">E-Mail</th> <th class="center" rowspan="1" colspan="1" style="display: none;">Opções</th> </tr> </tfoot> <tbody> <tr id="21" role="row" class="odd parent selected"> <td class="sorting_1" tabindex="0">21</td> <td>JACENI FERRARI ALENCAR</td> <td>R ARAGUAIA</td> <td>PARQUE CHUNO</td> <td>DUQUE DE CAXIAS</td> <td style="display: none;">RJ</td> <td style="display: none;">35637685</td> <td style="display: none;">BRADESCO (B)</td> <td style="display: none;">02570293709</td> <td style="display: none;">jaceni@ig.com.br</td> <td class=" center" style="display: none;"><button type="button" data-toggle="tooltip" title="Editar" class="editar btn btn-primary"><i class="fa fa-pencil-square-o"></i></button> <button type="button" class="eliminar btn btn-danger" data-toggle="modal tooltip" title="Apagar" data-target="#modalEliminar"><i class="fa fa-trash-o"></i></button></td> </tr> <tr class="child"> <td class="child" colspan="5"> <ul data-dtr-index="0" class="dtr-details"> <li data-dtr-index="5" data-dt-row="0" data-dt-column="5"><span class="dtr-title">UF</span> <span class="dtr-data">RJ</span></li> <li data-dtr-index="6" data-dt-row="0" data-dt-column="6"><span class="dtr-title">Telefone</span> <span class="dtr-data">35637685</span></li> <li data-dtr-index="7" data-dt-row="0" data-dt-column="7"><span class="dtr-title">Convênio</span> <span class="dtr-data">BRADESCO (B)</span></li> <li data-dtr-index="8" data-dt-row="0" data-dt-column="8"><span class="dtr-title">CPF</span> <span class="dtr-data">02570293709</span></li> <li data-dtr-index="9" data-dt-row="0" data-dt-column="9"><span class="dtr-title">E-Mail</span> <span class="dtr-data">jaceni@ig.com.br</span></li> <li data-dtr-index="10" data-dt-row="0" data-dt-column="10"><span class="dtr-title">Opções</span> <span class="dtr-data"><button type="button" data-toggle="tooltip" title="Editar" class="editar btn btn-primary"><i class="fa fa-pencil-square-o"></i></button> <button type="button" class="eliminar btn btn-danger" data-toggle="modal tooltip" title="Apagar" data-target="#modalEliminar"><i class="fa fa-trash-o"></i></button></span></li> </ul> </td> </tr> <tr id="23" role="row" class="even"> <td class="sorting_1" tabindex="0">23</td> <td>PEDRO HENRIQUES MARTINS SOUZA</td> <td>rua 18 de outubro 241 101</td> <td>tijuca</td> <td>RIO DE JANEIRO</td> <td style="display: none;">RJ</td> <td style="display: none;"></td> <td style="display: none;">CASSI</td> <td style="display: none;"></td> <td style="display: none;"></td> <td class=" center" style="display: none;"><button type="button" data-toggle="tooltip" title="Editar" class="editar btn btn-primary"><i class="fa fa-pencil-square-o"></i></button> <button type="button" class="eliminar btn btn-danger" data-toggle="modal tooltip" title="Apagar" data-target="#modalEliminar"><i class="fa fa-trash-o"></i></button></td> </tr> </tbody> </table>
This discussion has been closed.