Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Mirko Jelic
Added: Feb 24, 2019 8:33 PM
Views: 34
Tags: react
  1.   const getPagingRange = (currentPages,{ min = 1, numOfPages = 7 , numOfButton = 5 } = {}) => {
  2.     if (numOfButton > numOfPages){
  3.       return numOfButton = numOfPages;
  4.     }
  5.  
  6.     let start = currentPages - Math.floor(numOfButton / 2);
  7.     start = Math.max(start, min);
  8.     start = Math.min(start, min + numOfPages - numOfButton);
  9.  
  10.     return Array.from({length: numOfButton}, (el, i) => {
  11.       return (start + i)
  12.     })
  13.   }