Coder Wrap provides free to use snippets Coder Wrap provides free to use snippets

Back to HTML
Preview Source Code
Download
HTML
CSS
/**Typeo CSS Start**/
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

* {
 box-sizing: border-box;
}

body {
 font-family: "Poppins", sans-serif;
 color: #444;
 box-sizing: border-box;
 margin: 0px;
}

.container {
 max-width: 1280px;
 width: 100%;
 padding: 0px 15px;
 margin: auto;
}

.container-fluid {
 width: 100%;
 padding: 0px 30px;
}

/**Typeo CSS End**/
.pagenation-group {
 display: flex;
 flex-flow: row wrap;
 justify-content: center;
 padding: 20px 0;
 align-items: center;
}

.pagenation-group button {
 user-select: none;
 -webkit-user-select: none;
 -moz-user-select: none;
 padding: 12px 24px 10px 24px;
 text-transform: uppercase;
 font-size: 16px;
 border: none;
 line-height: 1.1;
 cursor: pointer;
 background-color: #3d3d3d;
 color: #fff;
 border-radius: 2px;
 margin: 0px 10px;
}

.pagenation-group button:hover {
 background-color: #000;
}

.pagenation-group .disabled {
 opacity: 0.5;
 pointer-events: none;
}

.pageno {
 text-transform: uppercase;
}

table {
 border: 1px solid #ccc;
 border-collapse: collapse;
 margin: 0;
 padding: 0;
 width: 100%;
 table-layout: fixed;
 margin: 30px 0px;
}

table tr {
 background-color: #f8f8f8;
 border: 1px solid #ddd;
 padding: .35em;
}
.showTabledata tbody tr:nth-child(n + 8) {
 display:none;
}
tbody tr:nth-child(2n+1) {
 background-color: #fff;
}

table th, table td {
 padding: 1em  2em;
 text-align: left;
}

table th {
 font-size: .85em;
 letter-spacing: .1em;
 text-transform: uppercase;
}

@media screen and (max-width:700px) {
 table {
  border: 0;
 }

 table caption {
  font-size: 1.3em;
 }

 table thead {
  border: none;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
 }

 table tr {
  border-bottom: 3px solid #ddd;
  display: block;
  margin-bottom: .625em;
 }

 table td {
  border-bottom: 1px solid #ddd;
  display: block;
  font-size: .8em;
  text-align: right;
  position: relative;
  padding-left: 80px;
 }

 table td::before {
  content: attr(data-label);
  float: left;
  font-weight: bold;
  text-transform: uppercase;
  position: absolute;
  left: 8px;
  top: 7px;
 }

 table td:last-child {
  border-bottom: 0;
 }

}
JS
var current_page = 1;
var records_per_page = 6;
var l = document.getElementById("listingTable").rows.length;

function prevPage() {
if (current_page > 1) {
current_page--;
changePage(current_page);
}
}

function nextPage() {
if (current_page < numPages()) {
current_page++;
changePage(current_page);
}
}

function changePage(page) {
var btn_next = document.getElementById("btn_next");
var btn_prev = document.getElementById("btn_prev");
var listing_table = document.getElementById("listingTable");
var page_span = document.getElementById("page");
listing_table.classList.remove('showTabledata');

// Validate page
if (page < 1) page = 1;
if (page > numPages()) page = numPages();

[...listing_table.getElementsByTagName("tr")].forEach((tr) => {
tr.style.display = "none"; // reset all to not display
});
listing_table.rows[0].style.display = ""; // display the title row

for (
	var i = (page - 1) * records_per_page + 1;
	i < page * records_per_page + 1;
	i++
) {
if (listing_table.rows[i]) {
	listing_table.rows[i].style.display = "";
} else {
	continue;
}
}

page_span.innerHTML = page + "/" + numPages();

if (page == 1) {
 btn_prev.classList.add('disabled');
} else {
 btn_prev.classList.remove('disabled');
}

if (page == numPages()) {
 btn_next.classList.add('disabled');
} else {
 btn_next.classList.remove('disabled');
}
}

function numPages() {
 return Math.ceil((l - 1) / records_per_page);
}

window.onload = function () {
 changePage(current_page);
};

Related Snippets

Leave a comment

Your email address will not be published. Required fields are marked *