Skip to content

Instantly share code, notes, and snippets.

@stanwmusic
Created July 10, 2025 06:15
Show Gist options
  • Save stanwmusic/a62272cb5c931110ab7fd4467717f6b5 to your computer and use it in GitHub Desktop.
Save stanwmusic/a62272cb5c931110ab7fd4467717f6b5 to your computer and use it in GitHub Desktop.
No Javascript Table with Pagination
- const ITEMS_COUNT = 95
- const DATA_COUNT = 20
.card
.table-title
h2 CSS ONLY TABLE
.button-container
span These buttons aren't working >
button.danger(title="Delete Selected")
svg(viewBox="0 0 448 512" width="16" title="trash-alt")
path(d="M32 464a48 48 0 0 0 48 48h288a48 48 0 0 0 48-48V128H32zm272-256a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zm-96 0a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zm-96 0a16 16 0 0 1 32 0v224a16 16 0 0 1-32 0zM432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16z")
button.primary(title="Add New Data")
svg(viewBox="0 0 512 512" width="16" title="plus-circle")
path(d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z")
.table-concept
- let counter = 1
- let itemsCount = Math.ceil(ITEMS_COUNT / DATA_COUNT)
- for (let i = 0; i < itemsCount; i++)
- let currentPage = (i * DATA_COUNT)
- let dataCount = DATA_COUNT
- let dataDisplay = ITEMS_COUNT - ((i + 1) * DATA_COUNT)
- if (dataDisplay < 0) {
- dataCount = Math.abs(dataDisplay)
- }
input(
type="radio"
name="table_radio"
id="table_radio_" + i
checked=i == 0
).table-radio
.table-display
| Showing #{currentPage + 1} to #{currentPage + dataCount}
| of #{ITEMS_COUNT} items
table
thead
tr
th
th No
th FIRST HEADER
th SECOND HEADER
th THIRD HEADER
th FOURTH HEADER
th FIFTH HEADER
tbody
- for (let j = 0; j < dataCount; j++)
tr
td
input(type="checkbox")
td #{counter}
td This is Item number 1-#{counter}
td This is Item number 2-#{counter}
td This is Item number 3-#{counter}
td This is Item number 4-#{counter}
td This is Item number 5-#{counter}
- counter++
.pagination
label(
for="table_radio_" + (i - 1)
class=(i == 0) ? "disabled" : ""
) &laquo; Previous
- for (let j = 0; j < itemsCount; j++)
label(
for="table_radio_" + j
id="table_pager_" + j
class=(i == j) ? "active" : ""
) #{j + 1}
label(
for="table_radio_" + (i + 1)
class=(i == itemsCount - 1) ? "disabled" : ""
) Next &raquo;

No Javascript Table with Pagination

Pagination made entirely by CSS. There is no single Javascript code here.

I used the radio button hack, and HTML and CSS loop to implement the pagination.

I also took advantage on position sticky CSS attribute, to have better view for layout.

If you compile the Pug source code into HTML, you will see the repetitive, pagination Elements, and "Showing x to y of z items".

The buttons above aren't working. Though, I still could add modal dialog for "Add New Data" function.

A Pen by Stan Williams on CodePen.

License.

// $card-max-width: 960px;
$card-max-width: 100%;
// $table-concept-max-height: 480px;
$table-concept-max-height: 100%;
$table-background-color: #ffffff;
$table-hover-background-color: darken($table-background-color, 8%);
$table-even-background-color: darken($table-background-color, 4%);
$table-header-color: #ffffff;
$table-header-background-color: #8f8f8f;
$pagination-background-color: #8f8f8f;
$pagination-label-color: #ffffff;
$pagination-label-background-color: $pagination-background-color;
$pagination-label-active-color: #ffffff;
$pagination-label-active-background-color:
darken($pagination-background-color, 15%);
$pagination-label-disabled-color: #ffffff;
$pagination-label-disabled-background-color:
lighten($pagination-background-color, 15%);
$table-title-color: #ffffff;
$table-title-background-color: #2f2f2f;
@import url("https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700");
@mixin button($background-color) {
background-color: $background-color;
&:hover {
background-color: lighten($background-color, 10%);
}
&:active {
background-color: darken($background-color, 10%);
}
}
body {
font-family: "Open Sans", sans-serif;
background-color: #e4e4e4;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.card {
background-color: #ffffff;
width: 100%;
max-width: $card-max-width;
max-height: 100%;
display: flex;
flex-direction: column;
box-shadow: 0 15px 35px rgba(#000000, 0.5);
}
.table-concept {
width: 100%;
height: 100%;
max-height: $table-concept-max-height;
overflow: auto;
box-sizing: border-box;
.table-radio {
display: none;
&:checked + .table-display {
display: block;
}
&:checked + .table-display + table {
width: 100%;
display: table;
}
&:checked + .table-display + table + .pagination {
display: flex;
& > label.active {
color: $pagination-label-active-color;
background-color: $pagination-label-active-background-color;
cursor: default;
}
& > label.disabled {
color: $pagination-label-disabled-color;
background-color: $pagination-label-disabled-background-color;
cursor: default;
}
}
}
.table-display {
background-color: #e2e2e2;
text-align: right;
padding: 10px;
display: none;
position: sticky;
left: 0;
}
table {
background-color: $table-background-color;
font-size: 16px;
border-collapse: collapse;
display: none;
tr {
&:last-child {
td {
border-bottom: 0;
}
}
th,
td {
text-align: left;
padding: 15px;
box-sizing: border-box;
}
th {
color: $table-header-color;
font-weight: normal;
background-color: $table-header-background-color;
border-bottom: solid 2px #d8d8d8;
position: sticky;
top: 0;
}
td {
border: solid 1px #d8d8d8;
border-left: 0;
border-right: 0;
white-space: nowrap;
}
}
tbody tr {
transition: background-color 150ms ease-out;
&:nth-child(2n) {
background-color: $table-even-background-color;
}
&:hover {
background-color: $table-hover-background-color;
}
}
}
.pagination {
background-color: $pagination-background-color;
width: 100%;
display: none;
position: sticky;
bottom: 0;
left: 0;
& > label {
@include button($pagination-label-background-color);
color: $pagination-label-color;
padding: 10px;
cursor: pointer;
}
}
}
.table-title {
color: $table-title-color;
background-color: $table-title-background-color;
padding: 15px;
h2 {
margin: 0;
padding: 0;
}
}
.button-container {
width: 100%;
box-sizing: border-box;
display: flex;
justify-content: flex-end;
span {
color: #8f8f8f;
text-align: right;
min-height: 100%;
display: flex;
align-items: center;
justify-content: center;
margin-left: 10px;
margin-right: 10px;
}
button {
font-family: inherit;
font-size: inherit;
color: #ffffff;
padding: 10px 15px;
border: 0;
margin: 0;
outline: 0;
border-radius: 0;
transition: background-color 225ms ease-out;
&.primary {
$background-color: #147eff;
background-color: $background-color;
&:hover {
background-color: lighten($background-color, 10%);
}
&:active {
background-color: darken($background-color, 10%);
}
}
&.primary {
@include button(#147eff);
}
&.danger {
@include button(#d11800);
}
svg {
fill: #ffffff;
vertical-align: middle;
padding: 0;
margin: 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment