Creating a pagination feature for an HTML table without using jQuery

Hello, I am relatively new to front-end development and currently undergoing training in a project involving HTML, CSS, and JavaScript. However, I seem to be facing an issue with the Table HTML element. I have created a table structure below:

A header Another header
First row
Second row

The table header contains search inputs that are designed to filter through the data within the table. My goal is to display a maximum of 5 rows per page, but when using the search function, it displays all the search results.

<table id="userstable" class="content-table">
          <thead>
            <tr>
              <th> <input type="text" class="search-input" placeholder="UserName"></th>
              <th> <input type="text" class="search-input" placeholder="Full Name"></th>
              <th> <input type="text" class="search-input" placeholder="Address"></th> 
              <th> <input type="text" class="search-input" placeholder="PhoneNum"></th> 
              <th> <input type="text" class="search-input" placeholder="Service"></th> 
              <th> <input type="text" class="search-input" placeholder="FUP"></th> 
              <th> <input type="text" class="search-input" placeholder="IP Address"></th> 
              <th> <input type="text" class="search-input" placeholder="Location"></th> 
          </thead>
          <tbody>
            <tr>
              <td>Ali</td>
              <td>Domenic</td>
              <td>Kobbeih</td>
              <td>+96170473654</td>
              <td>2M-4GB-230,000</td>
              <td>0</td>
              <td>192.324.422</td>
              <td>432.343,42.2342</td>
            </tr>

I am seeking advice on how to implement pagination into my current table so that only 5 results are displayed per page. Any insights or suggestions would be greatly appreciated!

Answer №1

To extract the inner HTML of the table you're working with, start by accessing it. Then, modify the HTML to create a new div for each "page". By adjusting the CSS class "visibility", you can display specific pages. I recommend storing each table page in a separate array variable so that every button click hides the previous page and reveals the next one.

let tableHtml = document.getElementById('pageOne').innerHtml;

tableHtml = /*insert your table HTML here*/;
<tbody id="pageOne">
<!-- content of your rows -->
</tbody>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Detecting file corruption from a form-based web page file upload (using input type="file")

Can file corruption occur during the process of uploading a file through a web form? Specifically, when an input of type "file" is included in a form submission and the file is saved on the server (typically in a designated temporary upload directory). Is ...

What is a reliable method for consistently updating backend C# with user-side JS data whenever it is altered?

I'm working on a front end JS application that includes visual sliders. I need to send the updated slider information to the C# backend (ASP.NET) whenever a user makes changes. After some research, it seems like AJAX is the most efficient way to achie ...

How can we access state data in a Vuex component once it is mounted?

My goal is to initialize a Quill.js editor instance in a Vue component once it is loaded using the mounted() hook. However, I am facing an issue where I need to set the Quill's content using Quill.setContents() within the same mounted() hook with data ...

Show a table with rows that display an array from a JSON object using JavaScript

My current code includes JSON data that I need to display in table rows, but I'm struggling to understand how to do so effectively. The output I am currently seeing is all the rows from the array stacked in one row instead of five separate rows as in ...

A step-by-step guide on disabling Google Analytics in a Next.js document.js file

Upon a user's initial visit to the website, they are presented with the option to either accept or decline tracking cookies. If the user declines, a cookie is set with the value of false. I am in need of a way to conditionally run the gtag script base ...

Generate a new entry and its linked data simultaneously

The Issue: Picture this scenario: I have two connected models, Library which has multiple Books: var Library = sequelize.define('Library', { title: Sequelize.STRING, description: Sequelize.TEXT, address: Sequelize.STRING }); var Boo ...

Bypassing 403 error in redux and react application

It appears that Redux or express is failing to handle an error scenario where a user updates their password using a reset password link token. https://i.sstatic.net/uo7ho.png https://i.sstatic.net/WGHdt.png An error message should be displayed as follow ...

Guide on transferring JSON information from a client to a node.js server

Below is the code snippet from server.js var express = require("express"), http = require("http"), mongoose = require( "mongoose" ), app = express(); app.use(express.static(__dirname + "/client")); app.use(express.urlencoded()); mongoose.con ...

The combination of jQuery and HTML FormData triggers an error message of "Uncaught TypeError: Illegal invocation."

I have been utilizing a particular script to upload my image files. You can find the script here: http://jsfiddle.net/eHmSr/ $('.uploader input:file').on('change', function() { $this = $(this); $('.alert').remove(); $ ...

When you select the checkbox button, a textfield and submit button will appear. Once you click the submit button, the checkbox button will be disabled

<td> <input type="checkbox" ng-model="alert.acknowledged" ng-disabled="alert.acknowledged" ng-click="onacknowledgedClick(alert)"></td> <td> <span ng-if="!alert.acknowledgeInProgress">{{alert.acknowledgedComments}}</span&g ...

What could be the reason behind the sudden inability of JavaScript prompt newlines to copy-paste into windows applications?

This function grabs the text from a single row in a table and shows it, alongside the text from the header row, in a prompt for users to copy and paste. It was functioning properly earlier, but now the newlines are not being included when pasting from the ...

Optimal approach for verifying the POST request payload

My RESTful API has a POST endpoint for user creation, and I am looking to implement data validation before inserting it into the database. There are two approaches I'm considering: Approach 1: Incorporating model validation in the controller and repe ...

Tips for updating Okta token when there are changes to claims

Currently, my react app is successfully using oauth (specifically okta), but I am encountering a problem. Whenever I modify the claims in the authorization server, the changes are not reflected in the app until the token expires or I perform a logoff and ...

Override existing Keywords (change false to true)

Are there any ways to overwrite reserved words? It's not something I would typically consider, but it has sparked my curiosity. Is it feasible to set false = true in JavaScript? I've come across instances on different websites where individuals ...

User-friendly toggle control (internet)

Need to implement a user role switch in the header of an internal application, with different content rendered based on the selected role. Trying to find an accessible solution using checkboxes, radios, and buttons: var button = document.querySelector(& ...

Customizing the renderInput of the Material UI DatePicker

Recently I integrated material-ui into my React project with TypeScript. I implemented the following code based on the example provided on the official website. import AdapterDateFns from '@mui/lab/AdapterDateFns'; import DatePicker from '@m ...

How can I generate a dummy JSON response using Backbone Fetch?

Exploring Backbone and looking for a way to simulate the response of a .fetch() call within a model without using a testing library or connecting to an external service. If the setting in the model is this.options.mock === true, I'd like to use an in ...

Switch up the font style of the title element

Is it possible to modify the font-family of the title attribute in an input field using either JavaScript or jQuery? <input type="text" title="Enter Your Name" id="txtName" /> ...

Tips for accessing the height property of an image

Is there a way to determine if an image lacks the height style property? Exploring CSS in HTML <img id="image" src="images/sports/sports9.png" style="width:100px"> Using jQuery if($('#image').css('height') == 0) { var ima ...

Hide a header and bring it back after a 2-second delay

I REPLIED BELOW Is there a way to make the header of my webpage fade out when scrolled and then be hidden using style.display? Here's what I have so far: <script type="text/javascript> function Scroll() { var head = document.getEl ...