jquery datatables: adding extra column

前端 未结 3 2001
轮回少年
轮回少年 2020-12-08 07:19

Scenario

I am using datatables (@version 1.9.4) for the first time to display data to the user. I succeed in retrieving the data via ajax and in bin

3条回答
  •  [愿得一人]
    2020-12-08 07:44

    Posting this answer here, just to show that where the aoColumnDefs needs to be defined. I got help from this question it self, but I struggled for a while for where to put the aoColumnDefs. Further more also added the functionality for onclick event.

    $(document).ready(function() {
      var table = $('#userTable').DataTable( {
            "sAjaxSource": "/MyApp/proctoring/user/getAll",
            "sAjaxDataProp": "users",
            "columns": [
                        { "data": "username" },
                        { "data": "name" },
                        { "data": "surname" },
                        { "data": "status" },
                        { "data": "emailAddress" },
                        { "data" : "userId" }
                      ],
            "aoColumnDefs": [
               {
                    "aTargets": [5],
                    "mData": "userId",
                    "mRender": function (data, type, full) {
                        return '';
                    }
                }
             ]
        } );
    
        $('#userTable tbody').on( 'click', 'button', function () {
            var data = table.row( $(this).parents('tr') ).data();
            console.log(data);
            $('#userEditModal').modal('show');
        });
    
    } );
    

提交回复
热议问题