Why can't DataTable get initialized properly in modal dialog

Why can't DataTable get initialized properly in modal dialog

mayuribmayurib Posts: 3Questions: 2Answers: 0

I am working on an application built in ASP.NET Core MVC and It has few modal popups displayed with datatables inside. But when ever it opens any popup datatable is not getting initialized correctly. It looks like a plain html table with no search, sort, pagination etc. I am loading a partial view in modal dialog as popup and once it is loaded, I am trying to initialize datatable in modal's 'shown-bs-modal' event but its not working. Below is my datatable initialization code and settings. Please suggest if i am missing anything or doing anything wrong

url = url.replace("statusId", statusVal);
$('#PendingItemsModel').find('.modal-title text').text("Pending Items");
$('#PendingItemsModel').find('.modal-body').load(url);
$('#PendingItemsModel').modal('show');
}
}

    $('#PendingItemsModel').on("shown.bs.modal", function () {
        //alert('test');


                $("#PendingItemsTable").DataTable({
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: true,
                    autoWidth: true,
                    searchable: true,
                    orderable: true,
                    destroy: true,
                    deferRender: true,
                    scrollY: 400,
                    language: {
                        "zeroRecords": " "
                    },
                    //deferRender: true,
                    //scroller: true,
                    "aLengthMenu": [[10, 20, 30, -1], [10, 20, 30, "All"]],
                    iDisplayStart: 0,
                    order: [[0, "asc"]],
                    columnDefs: [
                        { targets: [6], searchable: false, orderable: false }
                    ]

                }).draw();

Answers

Sign In or Register to comment.