Create a Event Handler for links that are not within the <li>
with class .active
, firing a Trigger for the event .submit
form, passing a parameter with the button number:
$(".pagination a").on("click", function(e){
e.preventDefault();
if(!$(this).parent().hasClass("active")) $('#form').trigger("submit", $(this).text().trim());
});
The if
above will prevent the link that is inside the li
with class .active
Fire Trigger. Maybe the active page doesn’t matter if it reloads, but if you want it to be enabled to click as well, just remove the if
:
$(".pagination a").on("click", function(e){
e.preventDefault();
$('#form').trigger("submit", $(this).text().trim());
});
Note that Trigger sends as parameter for event .submit
the text of the link, then you need to put in the event function .submit
a second variable to receive this information:
$('#form').submit(function (e, v) {
↑
Now just concatenate in the controller URL the parameter of the page that will be sent via GET:
url: '/module/controller/action'+ (v ? '?pagina='+ v : ''),
The ternary operator will check whether the variable v
has some value and concatenate in the controller URL the parameter ?pagina=
plus the value in v
(in place of pagina
you use the name you think best).
In the controller you will receive the value in pagina
with $_GET['pagina'];
. The form itself you will receive normal with $_POST
.
If pagination links are being created on the page after loading the page, change the Event Handler for the form below (delegated form):
$(document).on("click", ".pagination a", function(e){
e.preventDefault();
$('#form').trigger("submit", $(this).text().trim());
});
Do you load the page by submitting a form? What form would that be and what is its relation to paging?
– Woss
@Andersoncarloswoss, is loaded the
view
after submitting the form. This form provides parameters that are used to filter the query in the database. Since there can be from 0 to more than 100K of records, my controller creates the page.– Victor Carnaval