mardi 29 octobre 2019

How To Count Data Row In the table

I Want to Count My data In the table to make a condition, but I have not found for the solution

I've tried to make a length in the javascript function but this method still doesn't work and i tried with size() but in the web console show error

Javascript Code

$('.btn_hapus').on('click', function() {
  var id_form = $('#textkode').val();
  var data_length = $("td").length;
  console.log(data_length);
   $.ajax({
     type: "POST",
     url: "<?= site_url('request/delete') ?>",
     dataType: "JSON",
     data: {
       id_form: id_form
     },
     success: function(data) {
     if (condition) {
        $('#ModalHapus').modal('hide');
        $('#ModalShow').modal('hide');
         $("tr[data-id='" + id_form + "']").fadeOut("fast", function() {
                        $(this).remove();
                    });
                    load_data();
                }
            }
        });
   return false;
});

I expect the data will be count 2, because in my database there are only 2 data, but when i use the length in the console result is 14

Aucun commentaire:

Enregistrer un commentaire