Bootstrap DataTable lacks responsiveness

Having trouble with my Bootstrap DataTable. I followed the documentation and added the necessary HTML and Javascript code, but the table is not responsive or flexing as expected. I have checked all the links and imports, so I'm unsure where the issue lies:

$(document).ready(function() {
    $("#feedback").DataTable({
        aaSorting: [],
        responsive: true,
        columnDefs: [
            {
                responsivePriority: 1,
                targets: 0
            },
            {
                responsivePriority: 2,
                targets: -1
            }
        ]
    });
    $('[data-toggle="tooltip"]').tooltip();
} );
<div id="div-feedback" class="container">
              <div class="row py-5">
                  <div class="col-12">
                        <table id="feedback" class="table table-striped table-bordered responsive" style="width: 100%;">
                        <thead>
                            <tr>
                                <th>#ID</th>
                                <th>Titolo</th>
                                <th>Commento</th>
                                <th>Valutazione</th>
                                <th>Azione</th>
                             </tr>
                        </thead>
                <tbody>
                    <% 
                        if ( feedback != null &&  feedback.size() != 0) {
                                    for ( FeedbackBean  fb: feedback) {
                            %>
                    <tr>
                        <td><%=fb.getIdFeedback() %></td>
                        <td><%=fb.getTitolo() %></td>
                        <td><%=fb.getCommento() %></td>
                        <td><%=fb.getValutazione() %></td>
                        <td><button type="button" class="btn bg-cart">Elimina</button></td>
                    </tr>
                  <%}} %>
                </tbody>
                    </table>
                </div>
            </div>
        </div>

Answer №1

Make sure to apply the responsive class to the parent container

<div class="table-responsive">
<table class="table table-striped table-bordered">...</table>
</div>

<div id="div-feedback" class="container">
  <div class="table-responsive">
    <table id="feedback" class="table table-striped table-bordered">
      <thead>
        <tr>
          <th>#ID</th>
          <th>Titolo</th>
          <th>Commento</th>
          <th>Valutazione</th>
          <th>Azione</th>
        </tr>
      </thead>
      <tbody>
        <% 
                        if ( feedback != null &&  feedback.size() != 0) {
                                    for ( FeedbackBean  fb: feedback) {
                            %>
          <tr>
            <td>
              <%=fb.getIdFeedback() %>
            </td>
            <td>
              <%=fb.getTitolo() %>
            </td>
            <td>
              <%=fb.getCommento() %>
            </td>
            <td>
              <%=fb.getValutazione() %>
            </td>
            <td><button type="button" class="btn bg-cart">Elimina</button></td>
          </tr>
          <%}} %>
      </tbody>
    </table>
  </div>
</div>

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

JavaScript in Internet Explorer is showing an error message stating that it is unable to access the property '0' of an undefined or null

JavaScript Code function update() { var newAmt = 0; var newtable = document.getElementById("tbl"); for ( var i = 0; i < newtable.rows.length; i++) { innerTable = newtable.rows[i].cells[0].childNodes[0]; if ( (innerT ...

Why does text display differently in HTML (Firefox) on Ubuntu compared to Windows 7?

When viewing the HTML and CSS code in Firefox on Windows, everything appears fine. However, when I view it in Firefox on Ubuntu, it looks out of place. How can this be corrected? Any suggestions? Additional information: The CSS code used for the text show ...

The hyperlink is not functioning properly because of the CSS code

I found a helpful menu on this site http://www.jqueryscript.net/menu/interactive-menu-css3-jquery.html However, I encountered an issue. When I click on <a href="1.html">Application 1</a> It doesn't redirect to 1.html as expected. The p ...

Assigning a property to the Next.js response object

I recently discovered a fascinating concept involving setting an attribute on the response object within a Next.js API handler and being able to access that attribute in subsequent requests. This functionality took me by surprise as I couldn't find an ...

How can I determine the size of the custom options dropdown in Magento?

I'm facing a challenging issue that I can't seem to crack. It might be because I'm still learning the ropes and struggling with technical jargon. Please bear with me as I try to explain my problem. Here is a summary of what I'm trying ...

Be patient for the complete loading of the image during an AJAX operation

My webpage includes an ajax action that loads a div containing an image on the left and text on the right. The issue I am facing is that the text loads first, aligned to the left, and then the image loads, causing the text to shift to the right, resulting ...

Can you explain what data-orig is and what its purpose is in a given context? What are the reasons for its use?

There is a PHP page that I am currently working on, and all of the fields have an attribute called "data-orig" except for two. When I leave these two fields blank, the page posts back successfully. However, when I enter values into these fields (text box ...

How can I use jQuery ajax to call a servlet and display the results in JSP?

I need to execute a servlet that will retrieve data from a database and store it in the request object. The goal is to display the resulting information in some.jsp using JSTL tags. $('#ownForm #myButton').click(function() { $.ajax({ ...

The event.submit/return true in JS/jQuery is not functioning as expected

Could someone lend a hand? I'm struggling with a validation script that checks an email form for content and a valid email. It's functioning correctly, but it's not submitting the form even when everything is correct - it just removes the er ...

Using the ol tag in Google Chrome browser

I'm dealing with an issue regarding a simple ol list in a div: <div class="one">Title<hr width="200px"> <ol> <li>One</li> <li>Two</li> <li>Three</li> </ol> </div> Here's the CSS ...

Create a visual representation after inserting

I have created an input feature that allows me to paste images by using CTRL-V. The process involves copying an image from the browser and pasting it into the input field using CTRL-V. The result is an image in base64 format. Is there a way to manipulate ...

Vue router displays a white screen instead of content

I have been working on a web application using vue.js for my frontend. I have set up my router, but for some reason, the pages are not rendering. I have double-checked everything and there are no errors in my code. Here is a snippet of what I have: App.vu ...

What is the best way to update a div element following a successful AJAX request?

Sharing my experience as I struggled to find a raw JavaScript solution among all the jQuery answers. I have a function that posts comments to a section, and I want the section to refresh after posting. However, my code seems to be failing to work as expec ...

Having difficulty moving the menu buttons to the right

Take a look at the code snippet below: https://jsfiddle.net/fcx0wkq3/1/ When you expand the result window, you'll notice the menu buttons on the left. I am trying to adjust the position of these menu buttons to bring them towards the center or the r ...

Retrieve the designated element from an array of JSON data in SPLUNK

As a newcomer to the world of Splunk, I am facing a challenge with handling JSON data. Here is an example of the JSON data I am working with: "request": { "headers": [ { "name": "x-real-ip", "value": "10.31.68.186" ...

Generate a JavaScript list using data retrieved through AJAX

Hello, I am working on a function that extracts information from XML data and displays markers on a Google map. My current challenge is to create a path between two points. Here is the code snippet for retrieving the data: $.ajax({ t ...

Card columns in Bootstrap 4 occasionally show varying column displays in Chrome compared to other web browsers

I'm encountering an issue where the cards in my cards-column are displaying differently on Chrome compared to Edge and Firefox. Most of the time, they show up in two columns, but not consistently across all pages. For example, one specific page is on ...

The outcome of comparing with Bcrypt is consistently a negative result

bcrypt.compare() is consistently returning false when used in conjunction with this code within the user model. It appears that this issue is specific to bcrypt-nodejs. User.pre('save', function (callback) { this.password = bcrypt.hashSync(thi ...

What is your approach to managing errors when using Facebook SDK functions such as FB.getLoginStatus()?

When using functions like FB.getLoginStatus(), there are certain circumstances where console errors may arise. One common error is: Given URL is not allowed by the Application configuration.: One or more of the given... The issue with these errors is t ...

Searchable select option with Bootstrap styling

The bootstrap select option is causing issues for me where it's not functioning properly. $(function() { $('.selectpicker').selectpicker(); }); .sc_table { height: 100vh; overflow: scroll; } <link href="https://cdn.jsdelivr.net/n ...