Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82314

Pagination not working correctly with AJAX source

$
0
0

Having this issue with a dynamically populated DataTable; the pagination info & buttons are correct but more than 5 results are being displayed.

Here's the code:

            let dT_CompChld = $('#dT_CompChld').DataTable({
                "pageLength": 5,
                "autoWidth": true,
                "lengthChange": false,
                "searching": false,
                "language": {
                    "emptyTable":  "No components have been added for assembly" + compNo
                },
                "serverSide": true,
                "ajax": {
                    "url": "/ajax/compheir.php",
                    "type": "POST",
                    "dataSrc": function (json) {
                        // console.dir("Data: " + json.data); // Log array to console
                        return json.data
                    },
                    "data": function(d) {
                        d.id = compID;
                        d.mode = "dtc"; // Populate Table
                    },
                    error: function(response, req, err){ console.log('CompPrnt Error:' + err + " | Response: " + response.data + " | CompID:" + compID);}
                },
                "columnDefs": [
                    {"orderable": false, "targets": "no-sort" },
                    {className: "fit text-center", "targets": [0,3]},
                    {className: "fit", "targets": [1]},
                    {className: "fit ralgn", "targets": [2]}
                ],
                "drawCallback": function (oSettings) {
                    let pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');
                    pagination.toggle(this.api().page.info().pages > 1);
                    let pagedetails = $(this).closest('.dataTables_wrapper').find('.dataTables_info');
                    pagedetails.toggle(this.api().page.info().pages > 0);
                }
            }); // DataTable

Viewing all articles
Browse latest Browse all 82314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>