2

I will have some pages and I have to apply pagination to them.

on small device (show only 2 page numbers):-

<<  <  1 | 2  >  >>

on medium and above devices (show all page numbers):

<<  <  1 | 2 | 3 | 4  >  >>

I am able to show all the page numbers on medium to large screens but the requirement is to show only 2 page numbers, at a time, on small screen devices. Please advice how to handle this responsive design, how to hide other numbers and show only 2 at a time on small screens?

https://jsfiddle.net/3rvm34a7/

Andy
  • 21
  • 2

3 Answers3

1

There are 2 ways to implement this :

1. Service side :

You can detect the HTTP user agent from server if you are using php or python etc. Accordingly you can send pagination html to the view.

2. Client side :

a) You can detect the device width or device agent from javascript. Then you hide the larger pagination if device is smaller and vice versa. Link : What is the best way to detect a mobile device in jQuery?

b) Using Css : You can apply class to link of pages 3,4. Use media query to hide these pages on smaller resolutions using simple css. However when i click on a page, make sure you update the page classes accoedingly and dynamically update the pagination HTML. Link : https://www.w3schools.com/css/css_rwd_mediaqueries.asp

Community
  • 1
  • 1
Mihir Bhende
  • 6,876
  • 1
  • 15
  • 30
1

This is a CSS solution for hiding the pages on smaller devices and showing them for larger devices JSfiddle.
It will also showing and hiding other pages when rotating the tablet / phone to landscape.

You can resize fiddle window to see how it works.

Nebojsa Nebojsa
  • 835
  • 5
  • 15
0

I updated your jsfiddle here: https://jsfiddle.net/3rvm34a7/1/

I added a "pg" class name to your list page numbers and added the following code.

if(screen.width < 500){
  var list = document.getElementsByClassName("pg");
  for(var i = 2; i < list.length; i++){
     list[i].style.display = 'none';
  }
}
Sterling Beason
  • 562
  • 4
  • 12