Search for Resources and Solutions

How to use the JS pagination in Midrub

I've invented an easy to use JS pagination for Midrub which could be implemented in several minutes and i'm using it in all apps and components.

The data-type is very important to detect page click.

Then via php i'm returning results(items), total and page's number. To generate the pagination i'm using this code:



// Set the page's number
Main.pagination.page = data.page;
            
// As parameters has the id of the area where is the pagination and total number of items
Main.show_pagination('.main #categories-manager', data.total);


The pagination will be generated, now to detect clicks on the pagination i'm using this code:



// Detects all pagination's clicks
$( document ).on( 'click', 'body .pagination li a', function (e) {
e.preventDefault();
        
// Get the page number
var page = $(this).attr('data-page');
        
// Verify which pagination it is based on data's type 
switch ( $(this).closest('ul').attr('data-type') ) {
            
    case 'categories':

        // Get Categories List By Page
        Main.get_categories_by_page(page);

        break;                 
            
}
        
// Display loading animation
$('.page-loading').fadeIn('slow');
        
});


The pagination is very simply to be created and for this reason i think my way is the easiest.


Was this article helpful?