Adjusting the Page Number Displayed in the Pagination Bar of DataTables

I'm in the process of customizing the pagination bar using DataTables. I've successfully added images for the Previous/Next buttons, but I want to change the appearance of the page numbers.

https://i.sstatic.net/WsLf5.jpg

Here is what I have accomplished so far:

https://i.sstatic.net/HsmTt.jpg

I am attempting to position page numbers 1 and 2 above the pagination bar with accompanying text. I am unsure how to achieve this.

This is my Jquery code:

$(document).ready(function() {
    $('#esignTable').DataTable({"pageLength":5, "pagingType":"full_numbers", "sDom": '<"top"flp>rt<"bottom"i><"clear">', "oLanguage": { 
        "sEmptyTable": " ", 
        "oPaginate": {
               "sNext": '<img src="../images/integration/SlowRight.jpg">',
               "sPrevious": '<img src="../images/integration/SlowLeft.jpg">',
               "sFirst": '<img src="../images/integration/FastLeft.jpg">',
               "sLast": '<img src="../images/integration/FastRight.jpg">',
             }
           }
    });
});

Answer №1

If you want to implement pagination input in your DataTable, you can utilize the input pagination plugin. Below is an example:

var table = $('#example').DataTable({
  pagingType: 'input',
  pageLength: 5,
  language: {
    oPaginate: {
       sNext: '<i class="fa fa-forward"></i>',
       sPrevious: '<i class="fa fa-backward"></i>',
       sFirst: '<i class="fa fa-step-backward"></i>',
       sLast: '<i class="fa fa-step-forward"></i>'
    }
  }   
})  

You can view a demo of this implementation at http://jsfiddle.net/s19r61z7/

In the demo, I have included

https://cdn.datatables.net/plug-ins/1.10.15/pagination/input.js
for reference.

I opted to use Font Awesome icons instead of images in this example, but you can customize it as per your preferences. To achieve this, I added

http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css
.

You can further customize the appearance using plain CSS, like so:

.dataTables_paginate input {
  width: 40px;
}

The final result will resemble something like this:

https://i.sstatic.net/KhpnM.png

Answer №2

After stumbling upon your post on datatables.net, I realized that my sample below is actually functional. Take a look at it here: http://jsbin.com/rireyog/edit?js,output

If you integrate my callback handler into your code, you should be able to achieve your desired outcome.

The callback function updates the appended span and then consistently returns "" to clear out the actual info block.

If time isn't an issue, you might consider creating a more visually appealing one using bootstrap and fontawsome instead of icons.

$(document).ready(function() {

    var table = $('#example').DataTable( {
        dom:"tip",
        data:dataset.data,
        select:"multi",
        "columns": [
            { "data": "name", "title":"Namee" },
            { "data": "position", "title":"Position" },
            { "data": "office" , "title":"Office"},
            { "data": "extn" , "title":"Phone"},
            { "data": "start_date", "title":"Start" },
            { "data": "salary" , "title":"Salary"} 

        ],

        pagingType:"full",
        "infoCallback": function( settings, start, end, max, total, pre ) {
            var api = this.api();
            var pageInfo = api.page.info();
            var str = 'Page '+ (pageInfo.page+1) +' of '+ pageInfo.pages;
                if($('.paginate_info').length > 0){
                    $('.paginate_info').html(str);
                }
                else {
                    $(".paginate_button.previous").after("<span class='paginate_info'>"+str+"</span>");
                }
                 return"";
            },
           language": {
               "paginate": {  "first": "<<",last:">>",next:">",previous:"<"}}
        } );

     } );

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

Prioritizing the validation of form controls takes precedence over redirecting to a different URL in Angular 2

Within an HTML page, there is a form with validation and an anchor tag as shown below: <form #loginForm="ngForm" (ngSubmit)="login()" novalidate> <div class="form-group"> <label for="email">Email</label> <i ...

Retrieve the unique identifier of the dynamically created button

I have been struggling to retrieve the ID of a dynamically generated button. I attempted to access the specific button ID and utilize it for beforeSend:function(id). However, my efforts were not fruitful. <?php session_start(); require_once "../aut ...

Ionic: setInterval/setTimer not functioning after 5 minutes in the background

In need of a timer that can send notifications via the OneSignal API after a user-defined time period is reached. Users can set the timer for any value between 1-59 minutes. Despite attempts to use the background mode plugin, specifically setInterval and s ...

AngularJS: Toggle footer visibility with custom message

My goal is to develop an Angular app using Intel XDK with 3 page scripts in index.html, each having a separate footer. The requirement is for the footer and its message to display and hide every 5 seconds when running each page. app.js app.controller(&ap ...

Sending two files to a Node server and retrieving a file through an ajax request

I need assistance with a process involving two file inputs and a button. When the button is clicked, I want to send the two files to the server for processing and then receive a new file as a result. HTML Structure <input id='file-input1' ty ...

Angular 5 arrays within arrays

I'm currently facing an issue with using ngFor on a nested JSON output. The outer loop is working as expected, but the inner loop is not functioning properly. Below is my code snippet: Typescript file import { Component, OnInit } from '@angula ...

Adjusting the size of menus and text on the screen

A while back, I enlisted the services of a web developer to create my website, but unfortunately, it was never properly optimized for resizing windows. Despite numerous attempts to contact him for fixes over the past 5 months, he claims to be too busy at t ...

Simplifying complex JSON structures by un-nesting arrays

Within my Formik form, I have 3 fields: MemberMemberID, EventEventID, and event_date. This form represents an event (such as a Tuesday club) taking place on a specific date and attended by various members. Formik stores the data in key-value pairs within ...

Interactive canvas feature in a browser window with scrolling capabilities (drag and drop functionality)

One challenge I'm facing is when drawing in a canvas on a browser window that has a vertical scrollbar. The figures are in the correct position, and it's possible to interact with them by grabbing and making connections. However, this interactio ...

Utilizing JQuery to Modify XML File Content

Looking to retrieve data from an XML file using jQuery and display it in a textbox? If you want changes made in the textbox to reflect back in the original XML file, there are ways to achieve this. Here is some code that can help: <html><head&g ...

A guide on extracting certain fields and values from a JSON structure

I received a JSON output from the response body that contains various details about a contract. My goal is to extract only two specific pieces of information: "contractId" "contractStatus" To achieve this, I'm utilizing JavaScri ...

Send the component to the Angular directive

I am currently working on a popup directive that is similar to the one found at https://github.com/angular-ui/bootstrap/blob/master/src/modal/modal.js My goal is to position the popup close to the element that triggered its opening. What would be the mos ...

JavaScript code to find a date within a specified range

I have developed a script that calculates the number of weeks between two specified dates. It then generates a table where the number of rows equals the number of weeks. The script can be viewed on JSFIDDLE Script: $('#test').click(function ...

Creating an image using tiles in HTML

I have divided an image into 48 tiles (8x6) using a method similar to "Cutting an Image into 9 pieces C#". Now, I want to reconstruct the original image in HTML. What is the most effective approach to achieve this? Initially, I attempted to use a table wi ...

Tips for Looping through an Object within another Object

Is there a way to retrieve values from an Object that contains another Object nested inside? I am not overly concerned about the keys, but it would be helpful if I could access them as well. Here is an example of the response: res = {data: {name: 'na ...

What is the best way to display a chosen item in a text input field?

https://i.stack.imgur.com/Qe5Ds.png Looking to create a similar design, but lacking the necessary expertise. What steps should I take or what is the specific term for this style? Seeking assistance in implementing this using jQuery, PHP, or JavaScript. A ...

One method to retrieve the id from the database when the button is clicked using ajax

In this particular scenario, I am working on a message thread that is inside a modal. The objective is to display a message thread for a specific individual based on their reference number. However, I am encountering an issue in passing the reference numbe ...

Is it possible to bind a function to data in Vue js?

Can a function be data bound in Vue? In my template, I am trying something like this: <title> {{nameofFunction()}}</title> However, when I run it, it simply displays 'native function' on the page. Any insights would be appreciated ...

Stopping the mouse from scrolling

I am facing an issue on my page where scrolling a textbox to the bottom causes the entire document to scroll as well. How can I prevent mouse scrolling on the document but still allow scrolling within the textbox when the mouse is over it? It's import ...

Use the :target selector to target HTML elements with various unique IDs

Is there a way to use the same CSS selector #Overlay:target that currently hides the overlay to show content instead, or is there a more effective method? Here's what I'm dealing with: I've implemented an overlay that displays a dismissible ...