-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationScript.js
59 lines (50 loc) · 2.18 KB
/
NavigationScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { fillMembersTable } from './AdminUIScript.js'
let currPageNumber = null;
export const onClickPageButton = (pageNumber, membersData) => {
console.log(pageNumber);
currPageNumber = pageNumber;
//const totalNoOfPages=Math.ceil(membersData.length / 10);
resetAndHighlightNavigationButton(pageNumber, Math.ceil(membersData.length / 10))
let pageStartIndex = (pageNumber - 1) * 10
let pageEndIndex = pageStartIndex + 9 < membersData.length ? pageStartIndex + 9 : membersData.length - 1
let currentPageMembersData = membersData.slice(pageStartIndex, pageEndIndex + 1)
console.log(currentPageMembersData);
fillMembersTable(currentPageMembersData);
}
const resetAndHighlightNavigationButton = (currPageNumber, totalNoOfPages) => {
for (let i = 1; i <= totalNoOfPages; i++) {
//console.log(i);
if (currPageNumber !== i) {
document.getElementById(`numberedButton${i}`).classList.remove('navigation-button-selected');
}
else {
document.getElementById(`numberedButton${i}`).classList.add('navigation-button-selected');
}
}
}
export const specialButtonsFunction = (totalNoOfPages, membersData) => {
let startPageButtonElement = document.getElementById('startPageButton');
startPageButtonElement.onclick = function () {
if (totalNoOfPages > 1) {
onClickPageButton(1, membersData);
}
}
let prevPageButtonElement = document.getElementById('prevPageButton');
prevPageButtonElement.onclick = function () {
if (currPageNumber - 1 >= 1) {
onClickPageButton(currPageNumber - 1, membersData);
}
}
let nextPageButtonElement = document.getElementById('nextPageButton');
nextPageButtonElement.onclick = function () {
if (currPageNumber + 1 <= totalNoOfPages) {
onClickPageButton(currPageNumber + 1, membersData);
}
}
let lastPageButtonElement = document.getElementById('lastPageButton');
lastPageButtonElement.onclick = function () {
if (totalNoOfPages > 1) {
onClickPageButton(totalNoOfPages, membersData);
}
}
}