Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

paginacion javascript

const listItems = [
	'Item 1',
	'Item 2',
	'Item 3',
	'Item 4',
	'Item 5',
	'Item 6',
	'Item 7',
	'Item 8',
	'Item 9',
	'Item 10',
	'Item 11',
	'Item 12',
	'Item 13',
	'Item 14',
	'Item 15',
	'Item 16',
	'Item 17',
	'Item 18',
	'Item 19',
	'Item 20',
	'Item 21',
	'Item 22'
];

console.log('hello Friends');
let list_elemnts = document.querySelector('#list');
let pagination_elemnts = document.querySelector('#pagination');

current_page = 1;
row = 5;

function DisplaysItems(current_page, row, items, wrapper) {
	wrapper.innerHTML = '';
	current_page--;
	// console.log(current_page);
	// console.log(row);

	let start = current_page * row;
	let end = start + row;
	// console.log(start);
	// console.log(end);
	// console.log(items);
	let PaginationItems = items.slice(start, end);

	PaginationItems.map((item) => {
		let items_elemnts = document.createElement('div');
		items_elemnts.classList.add('item');
		items_elemnts.innerText = item;
		wrapper.appendChild(items_elemnts);
	});
}
function setUpPagination(items, row, pagination_elemnts) {
	pagination_elemnts.innerHTML = '';
	let PageCount = Math.ceil(items.length / row);
	for (let i = 1; i < PageCount + 1; i++) {
		let btn = PaginationButton(items, i);
		pagination_elemnts.appendChild(btn);
	}
}
function PaginationButton(items, page) {
	let button = document.createElement('button');
	button.innerText = page;
	if (current_page === page) {
		button.classList.add('active');
	}
	button.addEventListener('click', function() {
		current_page = page;
		DisplaysItems(current_page, row, items, list_elemnts);
		let current_btn = document.querySelector('.pagenumbers button.active');
		current_btn.classList.remove('active');
		button.classList.add('active');
	});
	return button;
}
DisplaysItems(current_page, row, listItems, list_elemnts);
setUpPagination(listItems, row, pagination_elemnts);
Comment

PREVIOUS NEXT
Code Example
Javascript :: js recursive fetch 
Javascript :: JavaScript Creating Symbol 
Javascript :: reactt split a value and sepate 
Javascript :: to do list app react code 
Javascript :: vuejs enter phone with country flag 
Javascript :: destructuring 
Javascript :: react-multi-carousel infinite loop causing issue 
Javascript :: blob to pdf javascript 
Javascript :: hook use effect with hooks 
Javascript :: form serialze submit button 
Javascript :: java script append element to array 
Javascript :: not equal to in js 
Javascript :: exchange value between 2 items in array javascript 
Javascript :: validar correo electronico en js 
Javascript :: what is == in js 
Javascript :: preventing form from submitting 
Javascript :: javascript img visible 
Javascript :: Repeat a String Repeat a String-Javascript 
Javascript :: how add class to ckeditor image 
Javascript :: use the whatwg url api instead 
Javascript :: js how to filter range imutable array 
Javascript :: sort array in ascending javascript 
Javascript :: ex: splide carousel 
Javascript :: react native layout animation android 
Javascript :: node js code for saving first middle and last name 
Javascript :: Backbone Router 
Javascript :: qr code terminal npm 
Javascript :: filter array js 
Javascript :: webpack.config.js 
Javascript :: send data with emit angular 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =