Stack Exchange
work of link is not proper
I am adding multiple rows in datatable with edit and delete link.Suppose I delete 3rd row and after that I edit the 5th row at that time edit link called function which is written on onclick event of delete link.
Here I am adding add,edit and delete functions of my code.
function addproduct() {

    if (document.getElementById("p_barcode").value == "" || wrongdata == false) {
        alert("Please Enter valid value of Barcode..!!!");
        return false;
    } else {
        var barcode = document.getElementById("p_barcode").value;
        var quantity = document.getElementById("p_qnty").value;
        var grossamount = document.getElementById("p_grossamount").value;
        var basetax = document.getElementById("p_basetax").value;
        var additionaltax = document.getElementById("p_additionaltax").value;
        var discount = document.getElementById("p_discount").value;
        var netamount = document.getElementById("p_netamount").value;
        var paidamount = document.getElementById("p_paidamount").value;

        var data = barcode + "," + quantity + "," + grossamount + "," + basetax + "," + additionaltax + "," + discount + "," + netamount + "," + paidamount;

        alert(data);

        var productdata = data.split(',');
        var table = $('#addpurchase').DataTable();

        table.row.add(
        [
        productdata[0],
        productdata[1],
        productdata[2],
        productdata[3],
        productdata[4],
        productdata[5],
        productdata[6],
        productdata[7],
        productdata[8] = "<a href='#' onclick='return rowedit();'> Edit </a> / <a href='#' onclick='return rowdelete();'> Delete </a>"])
            .draw();

        document.getElementById("p_barcode").value = "";
        document.getElementById("p_qnty").value = "1";
        document.getElementById("p_grossamount").value = "";
        document.getElementById("p_basetax").value = "";
        document.getElementById("p_additionaltax").value = "";
        document.getElementById("p_discount").value = "";
        document.getElementById("p_netamount").value = "";
        document.getElementById("p_paidamount").value = "";

        return false;
    }

}

function rowdelete() {

    var table = $('#addpurchase').DataTable();

    $('#addpurchase tbody').on('click', 'a', function () {
        var tr = $(this).closest("tr");
        var rowindex = tr.index();
        //alert(rowindex);
        table.row(rowindex).remove().draw(false);
    });
    return false;

}

function rowedit() {

    var table = $('#addpurchase').DataTable();

    $('#addpurchase tbody').on('click', 'a', function () {
        var tr = $(this).closest("tr");
        var rowindex = tr.index();
        alert(rowindex);
        var fetchdata = table.row(rowindex).data();
        alert(table.row(rowindex).data());

        document.getElementById("p_barcode").value = fetchdata[0];
        document.getElementById("p_qnty").value = fetchdata[1];
        document.getElementById("p_grossamount").value = fetchdata[2];
        document.getElementById("p_basetax").value = fetchdata[3];
        document.getElementById("p_additionaltax").value = fetchdata[4];
        document.getElementById("p_discount").value = fetchdata[5];
        document.getElementById("p_netamount").value = fetchdata[6];
        document.getElementById("p_paidamount").value = fetchdata[7];

        table.row(rowindex).remove().draw(false);

    });
    return false;

}


What is the question?

Could u explain your problem clearly mate..??

suppose i have 8 row in my datatable. First I delete 5th row from table and after that i click on the edit link of 8th row,function of onclick event of edit link is not called and row is delete from datatable.I have edit and delete link one column of datatable.

Ah.. thank heavens for Knockout / Angular.

Your are calling different function but have same event listener. You need to change your code to this and try:
Replace the function rowedit() and rowdelete() with the following code: 
$(document).ready(function(){
  $('#addpurchase tbody').on('click', 'a', function() {
    var action = $(this).data('action'); //Or you can use var action = $(this).attr('data-action');
      var tr = $(this).closest("tr");
      var rowindex = tr.index();
      if(action == 'edit'){
            //YOUR EDIT CODE
      }else{
            //YOUR DELETE CODE
      }

  });
});

and change below line in your addproduct() function:
productdata[8] = "<a href='#' data-action='edit'> Edit </a> / <a href='#' data-action='delete'> Delete </a>" ])


@user3045691 How is anyone meant to help you if all you tell them is "this code is not working :(" ... Take the approach from the code and learn from it instead of expecting a working out of the box solution.

function is not being called on click of link.
