Embedding directional arrows within a container div housing a horizontal-scrolling table

I am currently working on a dynamic table that is populated using AJAX. This table has multiple columns and is designed to scroll horizontally when the content overflows. However, I want to enhance user experience by adding navigation arrows on either side of the visible part of the table for easy movement left and right, similar to a Bootstrap carousel. The unique feature I aim to incorporate is having these arrows move up and down within the visible section of the table as the page itself scrolls.

While I understand how to implement horizontal scrolling on button click, I am struggling with placing these navigation arrows effectively. Can someone provide suggestions on achieving this functionality using CSS, jQuery, or a combination of both, or any alternative approaches?

Below is the HTML code structure:

<div id="table_div" style="display:none;">
    <div style="overflow-x: scroll; position:relative;" id="tablecontent">
        <table id="table" class="table table-striped table-hover">
            <thead class="vd_bg-green vd_white">

                <tr>
                    <th>Edit</th>
                    <th>Student Id</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Father's Name</th>
                    <th>Address</th>
                    <th>DOB</th>
                    <th>Mobile</th>
                    <th>Email</th>
                    <th>Gender</th>
                    <th>Start Year</th>
                    <th>End Year</th>
                    <th>Registration No</th>
                    <th>Roll No</th>
                    <th>Stream</th>
                    <th>Section</th>
                    <th></th>
                </tr>
            </thead>
            <tbody id="table_body">
                <tr>

                <!--Data generated dynamically via AJAX will be inserted here-->

                </tr>
            </tbody>
        </table>
    </div>
</div>

Answer №1

attempting: html:

<button class="left">left</button><button class="right">right</button>

styling:

div.dataTables_wrapper {
        width: 800px;
        margin: 0 auto;
    }
button {
    position: fixed;
    top:100px;
}
.right {
    right:0;
}

coding in javascript:

$(document).ready(function() {
    $('#example').DataTable( {
        "scrollX": true,
        "bPaginate": false
    } );

} );
$('button').on('click',function(){
     var pwidth = $('div.dataTables_wrapper').width();

    if($(this).hasClass('left')){
       $('.dataTables_scrollBody').scrollLeft( $('.dataTables_scrollBody').scrollLeft()-pwidth );
    } else {
        $('.dataTables_scrollBody').scrollLeft($('.dataTables_scrollBody').scrollLeft()+pwidth );
    };


});

https://jsfiddle.net/tuuga07h/1/

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

Tips for inserting an element in the middle of two elements using HTML

Here is the current structure of my DOM: <body> <h1> </h1> <button> </button> <p> </p> I am trying to dynamically add another p element in between the button and the existing paragraph when the button is cl ...

Conceal Bootstrap Toast for a day following dismissal

I have implemented Bootstrap 5 toasts to showcase an advertisement on my website. The goal is to make the advertisement disappear for 24 hours once the user closes it. Here's the current code snippet: <div class="position-sticky bottom-0" ...

Creating an Http interceptor in Ionic 3 and Angular 4 to display a loading indicator for every API request

One of my current challenges involves creating a custom HTTP interceptor to manage loading and other additional functions efficiently. Manually handling loading for each request has led to a considerable increase in code. The issue at hand: The loader is ...

Unable to locate AngularJS controller

As my single controller started to become too large, I decided to split it into multiple controllers. However, when I try to navigate to /signup, I encounter an issue where my UserController cannot be found. The error message states: Error: [ng:areq] Argu ...

Ways to determine the number of duplicate items in an Array

I have an array of objects that contain part numbers, brand names, and supplier names. I need to find a concise and efficient way to determine the count of duplicate objects in the array. [ { partNum: 'ACDC1007', brandName: 'Electric&apo ...

Determine the total number of rows present in a Selenium web table

I have a web table in a page that only has one attribute, which is the class. I am trying to determine the number of rows in this table. The code below works, but it provides me with the count of all web tables that have their parent class set as OverviewT ...

Adjust the HTML layout based on the JSON data provided

I am working with a JSON script that contains live matches, which change every 5 minutes. The changes could involve keys such as live_in or score. Matches are also being deleted and added to the JSON. I want to ensure that my HTML output remains updated at ...

Hidden Password Field Option in HTML

My HTML password textbox has the input type set as password, but I can still see what is being typed. This shouldn't happen as password inputs should be masked. Can someone please advise me on how to resolve this issue? To replicate, copy the code be ...

using jtemplates to append content rather than replacing it

Currently, I am utilizing jtemplates as my preferred templating solution (a fantastic jQuery plugin). Replacing my asp.net updatepanels with this tool has tremendously boosted the speed of my website. The only snag I've hit is when loading user commen ...

Steps to load a script when the document is ready:

What is the best method to include JavaScript using the following code: <script type="text/javascript" src="http://uads.ir/l.php?s=125125&w=5307cd5c027373e1773c9869"></script> only after the page has fully loaded? $(document).ready(funct ...

Navigate through a filtered list of parent items with the use of cursor arrows in AngularJS

My form contains an input with a dropdown, where I display JSON data like this: { "title": "Parent #1", "child" : [ {"title": "Child ##1"}, {"title": "Child ##2"}, {"title": "Child ##3"}, {"title": "Child ##4"} ...

Organize table cells based on decimal places

Organize the table cells based on their decimal points. Plunker Sample JSON: [ { "data1": [ { "name": "Download", "id": "1.1.1" }, { "name": "Download", ...

Tips for disabling automatic sliding in Bootstrap 5 carousel specifically on larger screens

I am working with a Bootstrap 5 carousel that I need to configure to stop autosliding on large screens, but maintain autoslide functionality on mobile devices. Is there a way to achieve this using only HTML and CSS/SCSS? I am aware of the data-bs-interval ...

Issue with passing values through radio buttons in a form

Can anyone explain why a small form with a radio button group is not passing any value to a php processing page? I have shared the code on Pastebin at the following link: http://pastebin.com/GT5HDpuc. Any help in identifying the issue would be greatly appr ...

Combining table rows using the <td> class in JavaScript

I am currently working on refining the JS code to merge rows with common values and classes in a table. The existing code successfully merged common rows but failed to consider their classes. Snippet of the Table code: <tbody id="property_dtl_table_bo ...

How can I focus on a particular P element within this Div using CSS?

I am attempting to target a paragraph element within the code snippet below. I want to create a class that applies text-shadow to the text of that specific paragraph. However, I am unsure which class to focus on and what the correct syntax should be. I in ...

Is it possible to target all children with CSS3 if a certain number of children are present?

I've been racking my brain trying to select all children if there are x or more children present. I want to be able to select all child elements if there are at least x children. So far, I've managed to target all children when there are exactl ...

Adjusting the CSS based on the screen's resolution and size

Currently, I am working with a client who needs interfaces to be adapted for two screens with a resolution of 2560x1600. The challenge is that both screens have the same resolution but different screen diagonals. One has a 27" diagonal and the other... on ...

The Jquery bind function does not work as expected when trying to handle 'ajax:success', 'ajax:error', or 'ajax:complete' events after submitting a form

After implementing the jQuery bind method, I am facing an issue where the 'ajax:success', 'ajax:error' or 'ajax:complete' callbacks are not being triggered. The form is submitted via Ajax and the data gets inserted into the da ...

Enhancing drag items in jquery UI Sortable with customizable drag images

Is there a method to include a drag image on the item being dragged? I attempted to achieve this using the code below: $('.selector').sortable({ start: function( event, ui ) { $(ui.item).addClass('dragImage'); } }); While t ...