Get table in the generation of tables in loop
Get table in the generation of tables in loop
Wilmer30
Posts: 33Questions: 10Answers: 1
I have the following html:
<?php
foreach ($lista as $key => $value) {
<?php
>
">Agregar
Id
Producto
Cantidad
Precio
Total
Acción
<?php foreach ($value['compras'] as $k => $val) { ?>
">
<?php echo $val['id'] ?>
<?php echo $val['producto'] ?>
<?php echo $val['cantidad'] ?>
<?php echo number_format($val['precio'], 2, '.', ' ') ?>
<?php echo number_format($val['precio'] * $val['cantidad'], 2, '.', ' ')?>
" alt="Editar"> ">
<?php
}
?>
<?php
}
>
```
And my Javascript:
```
var table = $('table.table').DataTable({
"paging": false,
"info": false
});
?>
......
if(datos.tipo == 'new'){
table.row.add([dat.data.id,
dat.data.producto,
dat.data.cantidad,
dat.data.precio,
dat.data.precio * dat.data.precio,
'edit/del']).draw( false );
}
From what I see the tables are generated 0,1,2,3,4....
When I create a record in table 3 is added in table 0, how can I get the table to which I should add the record?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
What I found is
tables()
andtable()
, how do I get what table I am on? to then work only with that table?You would use the table-selector that would select one or more of your tables as desired. There are examples on the page of how to use the selectors for various conditions.
Kevin
thanks for answering.
I have the following examples:
in the first line I can get the row of the table 0, in the following I do not return anything, then how do I get the index of the table when clicking?
Ok, I solved:
table.table( this.parentNode.parentNode ).row();
Thank you kthorngren .
I would look at using the Select Extension and using the
select
to get the data of the selected row. Here is an example of how this works:http://live.datatables.net/foxorulo/1/edit
It will show on the console the name of the person selected.
EDIT: noticed I posted this after you solved your issue. Maybe it will be useful to you or someone else.
Kevin