Pager not updating after loading from server-side.

Pager not updating after loading from server-side.

jeanguysjeanguys Posts: 3Questions: 1Answers: 0

Using 1.10.16 with bs3 styling.

We have a (potentially) large data set and enabled server-side processing. Everything is working fine, data is returned, search is right, total record count and filtered count is right. The problem is that when I click into page 2, the page 2 data loads correctly but the pager itself continues to show "Showing 1 to 10 of 11 entries (filtered from 141 total entries)" (for example) and page 1 button is still selected (it's as though the pager thinks we're still on page 1). So I can neither get back to page 1 nor click into any page number not showing when the pager thinks we're on page 1.

Unfortunately I can't provide a live example as this is an internal app.

What would be the cause for this?

Init code:

                this.dataTable = $('#'+this.tableId).DataTable({
                    "searching": true,
                    "ordering": true,
                    "processing": true,
                    "serverSide": true,
                    "deferRender": true,
                    "columnDefs": [ {
                        "targets": suppressedCols,
                        "orderable": false
                    } ],
                    "ajax": {
                        "url": dataUrl,
                        "type": "POST",
                    },
                    "createdRow": function(row, data, dataIndex) {
                        self.dataTable.columns.adjust().draw();

                        var cb = $(row).find('.row-select-checkbox');
                        var rowId = cb.data('row-id');
                        var isChecked = self.selectedIds.indexOf(rowId);
                        if (isChecked !== -1) {
                            cb.prop("checked", true);
                        }

                        cb.change(function() {
                            self.setCheckbox(cb, this.checked, rowId, self.selectedIds, self.updateSelectedCount);
                            return false;
                        });
                    }
                });

Any help appreciated, thanks!

Answers

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin

    You have server-side processing enabled. Is the script that your dataUrl variable is pointing to correctly returning the expected data? What is it returning?

    Allan

  • jeanguysjeanguys Posts: 3Questions: 1Answers: 0

    Yes, the data, total count, filtered count, etc is all correct. The table is working exactly as intended with the exception that the pager is not updating. Is there some return value that is being expected to advance the paging? Here is my response json:

            return response()->json([
                'draw' => intval($input['draw']),
                'recordsTotal' => count($account->campaigns),
                'recordsFiltered' => count($campaigns),
                'data' => $data,
            ]);
    

    My understanding is that the draw parameter is the necessary value to associate the request with the response.

    Thanks!

  • jeanguysjeanguys Posts: 3Questions: 1Answers: 0

    Figured out what was causing it. We have a call to

    dataTable.columns.adjust().draw()
    

    in our createdRow callback. Removing it restores paging.

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin

    You could use .draw( false ) to keep the pacing in place (draw()).

    Allan

This discussion has been closed.