CodeIgniter Forums
Fetch data in a selected table row - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Fetch data in a selected table row (/showthread.php?tid=68313)

Pages: 1 2


RE: Fetch data in a selected table row - Wouter60 - 06-26-2017

The problem is in this line of your script:
Code:
$('#ppmpsupplies').on('click', 'tr', edit_item( <?php echo $item->id ?> ));

If you echo a php value in a script section of your page, it is done when the page is outputted by php. This happens only once, so the value of $item->id is the last $item->id php recognizes.
It's better to add a data-id property to each table row (or the button that will trigger AJAX).
Once you start your AJAX action, you can refer to the data-id property of the selected row.


RE: Fetch data in a selected table row - Junie - 06-26-2017

(06-26-2017, 11:28 PM)Wouter60 Wrote: The problem is in this line of your script:
Code:
$('#ppmpsupplies').on('click', 'tr', edit_item( <?php echo $item->id ?> ));

If you echo a php value in a script section of your page, it is done when the page is outputted by php. This happens only once, so the value of $item->id is the last $item->id php recognizes.
It's better to add a data-id property to each table row (or the button that will trigger AJAX).
Once you start your AJAX action, you can refer to the data-id property of the selected row.
Yes sir,
That's the code above given by paradinight. The problem now is the error I mentioned above. When I try to switch the parameters (id, element) the functionality of delete works but still the error undefined appears. Thanks for the time.


RE: Fetch data in a selected table row - Paradinight - 06-27-2017

Code:
callback: function(item, id) {
                              var id = $(this).closest('tr').data('id');
                               delete_item(this,id);
                               return true;
                           }