0

I used dataTable in my project and I added a custom column to it with edit and delete button. I am able to pass individual fields to function. Is it possible to pass while object as argument to function?

Below is my dataTable code:

<script type="text/javascript">
    var table1;
    $(function(){

        table1 = $('#simpletable').DataTable({
        processing  :true,
        serverSide  :true,
        //table: '#simpletable',
        ajax    :"{{route('shippingPreference.create')}}",
        columns   :[

        // { data: "id" },
        { data: "channel_name" },
        { data: "process_type" },
        { data: "method_name" },
        { data: "market_place_shipping_method_name" },
        {
            sortable: false,
            "render": function ( data, type, full, meta ) {
              console.log(full);
              var actionhtml='<button data-toggle="tooltip" data-placement="top" id="'+full.id+'" title="Remove" type="button" class="btn btn-danger btn-xs" >' +
                    '<i class="fa fa-times-circle" aria-hidden="true"></i></button><a data-toggle="tooltip" data-placement="top" data-original-title="Edit"  class="btn btn-info btn-xs" onclick="callMe('+full+')">'+
                    '<i class="fa fa-edit" aria-hidden="true"></i></a>';
                return actionhtml;
            }
        }
    ],
    } );
 });
3
  • What happens when you run the above code? Commented Jul 17, 2017 at 9:30
  • it give error, undefined.. Commented Jul 17, 2017 at 10:16
  • I think the problem is that you're effectively trying to print out the full object as part of the <a> tag, so you may have to use JSON.stringify(full) Commented Jul 17, 2017 at 10:29

1 Answer 1

1

As @markpsmith told, you have to use JSON.stringify(full) and use single quote instead of double quote in your code:

var actionhtml='<button data-toggle="tooltip" data-placement="top" id="'+full.id+'" title="Remove" type="button" class="btn btn-danger btn-xs" >' +
                    '<i class="fa fa-times-circle" aria-hidden="true"></i></button><a data-toggle="tooltip" data-placement="top" data-original-title="Edit"  class="btn btn-info btn-xs" onclick=\'callMe('+JSON.stringify(full)+')\'>'+
                    '<i class="fa fa-edit" aria-hidden="true"></i></a>';
Sign up to request clarification or add additional context in comments.

Comments

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.