Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTable serverside processing adding edit column

I'm using datatable 1.10.13 serverside processing. And I want to add a column 'edit' with edit user link. How to do this?

My js file

$('#userTable').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "type": "GET",
        "url": "",
        "dataSrc": "data",
        "contentType": "application/json; charset=utf-8",
        "dataType": "json",
        "processData": true
    },

    "columns": [
        { "data": "id" },
        { "data": "email" },
        { "data": "" }, //edit link column
    ]
} );

DataTable view php

<table cellspacing="0" id="userTable" class="display">
    <thead>
    <tr>
        <th class="ui-state-default">Name</th>
        <th class="ui-state-default">Email</th>
        <th class="ui-state-default">EDIT</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>

please advise


1 Answers

you need to define the render property with the callback that how to render the column by providing the html which would be :

"columns": [
        { "data": "id" },
        { "data": "email" },
        { "data": "id",
          "searchable": false,
          "sortable": false,
          "render": function (id, type, full, meta) {
                                    return '<a href="/user/userdata/'+id+'"><i class="fa fa-pencil"></i></a>';
                                } 
        },
    ]
like image 80
Ehsan Sajjad Avatar answered Jul 04 '26 11:07

Ehsan Sajjad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!