2

In my codeigniter project i'm using a Table in which it is dynamically generated by Ajax. on the each row there is a button to Delete the corresponding row from Html Table and Mysql table too.

i tried it already. and i get the code to remove Html table row , and it follows

$(document).on('click', '#deleteRow', function() {

     $(this).parent().parent().remove();

});

and it worked. but i want to delete that corresponding row from Mysql too. so first of all , it needs to be pass the corresponding row informations from javascript. then pass this to the Controller via URL.?

window.location.href = "<?php echo base_url("settings/remove_company"); ?>?id="+current;

How i get corresponding row informations such as company_id, lic_id (field names of html table).? any help would be greatly appreciated .

ecnepsnai
  • 1,882
  • 4
  • 28
  • 56
Shifana Mubi
  • 197
  • 1
  • 3
  • 17
  • 1
    make each row unique then call a function on your delete button.make function that make ajax request to delete that row ,when response is recive remove element by using your unique ID – Ranjeet Singh Dec 18 '14 at 13:15

1 Answers1

3

Add attributes to the <tr>

<tr data-companyId="<?php echo $companyId;?>" data-licId="<?php echo $licId;?>">

In your jQuery, get those attributes on click of delete link:

$(document).on('click', '#deleteRow', function() {     
  var companyId = $(this).parent().parent().attr('data-companyId');
  var licId = $(this).parent().parent().attr('data-licId');
  $(this).parent().parent().remove();
});

Even, you can do object caching (using variable instead of object to improve performance.

$(document).on('click', '#deleteRow', function() {
  var obj = $(this).parent().parent();
  var companyId = obj.attr('data-companyId');
  var licId = obj.attr('data-licId');
  obj.remove();
});
Pupil
  • 23,834
  • 6
  • 44
  • 66