3

I put edit a button but how can I pass id of each row. Its server side data table but I don't know how get id for edit and button

 <script type="text/javascript" language="javascript" >
        $(document).ready(function() {
            var dataTable = $('#employee-grid').DataTable( {
                "processing": true,
                "serverSide": true,
                "ajax":{
                    url :"packing-grid-data.php", // json datasource
                    type: "post",  // method  , by default get
                    error: function(){  // error handling
                        $(".employee-grid-error").html("");
                        $("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
                        $("#employee-grid_processing").css("display","none");
                    },

                },

                "columnDefs": [
                {

                    "data": null,
                    "defaultContent": "<a href='view_product.php?id=' name='edit' class='btn   btn-primary'> VIEW </a>",

                    "targets": -1
                    }
                ]

            });
        });


    </script>

1 Answer 1

2

There are two ways you can do this:

  1. You can prepare the Edit and Delete button html in the PHP code and pass it in ajax response

  2. Using datatable jquery createdRow callback.Check below code. In the code data[1] means id value from database.

    var dataTable = $('#employee-grid').DataTable( { "processing": true, "serverSide": true, "ajax":{ url :"packing-grid-data.php", type: "post", error: function(){ $(".employee-grid-error").html(""); $("#employee-grid").append('No data found in the server'); $("#employee-grid_processing").css("display","none"); }, }, "columnDefs": [ { "data": null, "targets": -1 } ], createdRow : function( row, data, dataIndex ) { $( row ).find('td:eq(-1)').html(' VIEW '); } });

Sign up to request clarification or add additional context in comments.

8 Comments

great. if you need any other help let me know. thanks
If my answer has solved your issue, vote me or give me your review
where's the option ??
Please check my above screenshot and give your favour
yaa i show that and i do that bt " You can't vote for your own post "i show that message
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.