jQuery Datatables go to a page

Asked

Viewed 64 times

0

I need to guess in my jQuery Datatable a function so that the user says he wants to go to page 9 and he is redirected. I used the following function:

$('#btnIrAtePag').on('click', function () {
    var table = $('#grid').DataTable();
    table.page($('#txtIrAtePag').val() - 1).draw(false);
});

But I wanted to add the button and input next to the pagination and I’m not getting it. Is there any other way to do this function?

  • Face the question is a little confused. Let’s see if you understand. You want to add an input where the user will enter the page number they want to go, right?

  • Opa, that’s right, @Cristianogilbertojoão

  • And you want to add the input as if it were a Datatable resource?

  • If possible, @Cristianogilbertojoão

1 answer

0


Well, I solved it as follows. I added the datatables initComplete parameter and added the elements I wanted..

initComplete: function () {
                var criaDivElementos = "<div class=\"pull-left\">";
                criaDivElementos += "<div class=\"input-group\">";
                criaDivElementos += "<input type=\"text\" id=\"txtIrAtePag\" class=\"form-control\" placeholder=\"Ir até a página..\">";
                criaDivElementos += "<span class=\"input-group-btn\">";
                criaDivElementos += "<input type=\"button\" id=\"btnIrAtePag\" class=\"btn btn-default\" value=\"Ir!\">";
                criaDivElementos += "</span>";
                criaDivElementos += "</div>";
                criaDivElementos += "</div>";

                $("#grid_info").append(criaDivElementos);
            },

Reference: https://datatables.net/reference/option/initComplete

Browser other questions tagged

You are not signed in. Login or sign up in order to post.