my-defined click event is called after all predefined click events on next paging button

my-defined click event is called after all predefined click events on next paging button

avnakuavnaku Posts: 2Questions: 2Answers: 0

Hi,

I have attached a click event on next paging button, when clicked show current page number, but it is not showing the right page number as when next button is clicked datatable is moving to next page and then my event is getting triggered which is showing the page number of the current page which is not the one on which next button has been clicked. A number of events are attached to the next button and My click event is always getting called in the last. How to make sure that it is called before all the click events or how to return the right page number.

function addClickEventListenerOnNextButton(tableId) {
    $(tableId + "_next").click(function () {
        var dataTable = $(tableId).DataTable();
        var pageInfo = dataTable.page.info();
        var isNextButtonEnabled = $(tableId + '_next.paginate_button.next.disabled').length > 0 ? false : true;

        if (isNextButtonEnabled && ((pageInfo.page + 1) >= pageInfo.pages)) {
            $("#loader_wrapper").show();

            $.ajax({
                type: "GET",
                url: getURL(tableId, getPageSize(tableId)),
                async: false,
                success: function (response) {
                    if (response.responseCode == "SUCCESS") {
                        loadResultAndRedrawTheTable(tableId, response);
                        increaseCallTimes(tableId);
                        $("#loader_wrapper").hide();
                        $('.load_failed').hide();
                    } else {
                        showErrorMessage("Loading new results failed, Error : " + response.message);
                    }
                },
                error: function () {
                    showErrorMessage("Loading new results failed, Please try after sometime.");
                }
            });
        }
    });
}

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @avnaku ,

    As I said in your other thread, have you considered using serverSide, since it appears that you're redesigning that functionality? If not, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

    Cheers,

    Colin

This discussion has been closed.