Search field in DataTables appears to be misaligned


I'm in the process of developing a small website using JSP and DataTables (currently only for the first table).
Here's what I have so far:


As you can observe, there seems to be an alignment issue with the search field position. I'm not sure what's causing this problem. What I want is for the end of the search field to stay within the boundaries of the bottom table.
Here is my HTML code :

<TABLE class="table table-striped table-bordered" id="usertable" style="max-width: 800px">
<thead>
        <TR>
            <Th colspan=2 align=center><FONT color="blue">Toto</font><br>
                <i> (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1859e859eb1859e859edf9394">[email protected]</a>) </i><b><FONT color = "red">Administrator</b></font>
            </Th>
            <Th colspan=1 align=center><a href="UserUpdate?action=update&id=2">
                <button type="submit" class="btn btn-default"><FONT color="green"><span class ="glyphicon glyphicon-user">
                </span> Edit my account</FONT>
                </button></a>
            </Th>
        </TR>

        <TR>
            <Th width=40% align="center"><span class ="glyphicon glyphicon-calendar"></span> Fishing Date</Th>
            <Th width=40% align="center"><span class="glyphicon glyphicon-dashboard"></span> Fish Weight (Kg)</Th>
            <Th width=20% align="center"><i>Action</i></Th>
        </TR>
</thead>

<tbody>
        <TR>
            <TD width=40% align="center">03-07-2014</TD>
            <TD width=40% align="center">24.0</TD>
            <TD width=20% align=center><a href="FlightUpdate?action=delete&idvol=1">
                <button type="submit" class="btn btn-default" onclick="return confirm('Ok to delete the flight?')">
                <FONT color="purple"><span class="glyphicon glyphicon-trash"></span> Delete fishing trip</FONT>
                </button></a></TD>
        </TR>
        <TR>
            <TD width=40% align="center">22-08-2014</TD>
            <TD width=40% align="center">42.0</TD>
            <TD width=20% align=center><a href="FlightUpdate?action=delete&idvol=2">
                <button type="submit" class="btn btn-default" onclick="return confirm('Ok to delete the flight?')">
                <FONT color="purple"><span class="glyphicon glyphicon-trash"></span> Delete fishing trip</FONT>
                </button></a></TD>  
        </TR>
</tbody>
</TABLE>

And here is my JS selector :

<script>
$(document).ready(function() {
    $('#usertable').dataTable( {
        "dom": '<"top"fp<"clear">>rt'
    } );
      //$('.carousel').carousel();
});
</script>


Of course, I am utilizing JQuery libraries as well:

<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/jquery.dataTables.css">
<link rel="stylesheet" href="css/jquery.dataTables_themeroller.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.min.js"></script>         
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>


Is there any suggestion on how to align sDom correctly?
Thank you very much!

Answer №1

The search bar in the data tables will stretch across the entire width of the screen, as demonstrated in your example with the viewport's full width. To rectify this issue, you must enclose the table within a wrapper element that defines the maximum width for the table to occupy.

<div style="max-width: 800px">
    <table class="table table-striped table-bordered" id="usertable" style="max-width: 800px">
     ........
    </table>
  </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

Incorporate JavaScript code into contentWindow

Attempting to utilize a Javascript postMessage function, similar to how it can be done with an iframe, but now with an embed element. The reason for using an embed is due to the bug in IOS devices which causes issues with setting iframe width and height. ...

Troubleshooting why passing $var within @{{ }} in Vue.js + Laravel is not functioning as expected

I am integrating Algolia Vue-InstantSearch into a Laravel Project. Since we are working with a blade file, the {{ }} symbols will be recognized by the php template engine. To ensure that they are only understood by Vue in JavaScript, we can add an @ prefix ...

When the Bootstrap dropdown-toggle is activated, the Jquery 'document on click' function fails to respond

The Challenge Currently, I have set up an event listener that hides a dropdown by removing a class when a click occurs outside of the dropdown: $(document).on('click', function(event) { if (!$(event.target).closest('#myDropdown').len ...

Is there a way to automatically scroll the parent page's top when the user navigates within an iframe?

We are encountering an issue with the loading of the iFrame. When the iFrame loads on the client's page, we notice that the page location jumps around and, in most cases, the page focus is lower down the page. This requires users to scroll up to view ...

"Create dynamic web pages with multilingual support using HTML, JQuery, and nested

For my multilingual website, I wrote this simple JQuery code: (function() { var language, translate; translate = function(jsdata) { $('[tkey]').each(function(index) { var strTr; strTr = jsdata[$(this).attr('tkey')] ...

Tips for making a div overlap with Twitter Bootstrap positioning

Currently, I am attempting to utilize Bootstrap 4.5 to position a div over two existing divs. Instead of explaining it through text, the image linked below provides a visual representation of what I am aiming for: https://i.sstatic.net/gbylW.png In this ...

Display a specific message in a div when the input field is left empty

My goal is to create a div that mirrors the content of an input field. When I type "lalala" in the input, it should show up in the div, and this part is working fine. However, I also want the div to display "The input is empty" when the input itself is emp ...

Using JavaScript to trigger actions via links or buttons inside a table will only function properly in the first row

After multiple consecutive Ajax requests to refill an HTML table, there seems to be a strange issue. The links in the first row of the table are functioning properly and call JavaScript functions, but for any subsequent rows, the links or buttons stop work ...

Strategies for incorporating a string into an ng-template using HTML

Suppose I have an ng-template as follows: <ng-template #templateRef> <button (click)="testClick()" Click me </button> <a I'm a link </a> </ng-template> Now, I want to utilize it in my html template li ...

Ways to interpret and contrast the information within files (verifying if the lengths of the strings are identical)

I have a web tool where users can upload text and code files, which are then saved in a local directory. I'm trying to create a function that reads these files, compares their lengths, and generates a report indicating whether they are equal or not. B ...

The inner radius remains constant in the Chart.js Doughnut Chart

I've been trying to create a half doughnut chart using Chart.js, similar to the image linked below. However, I'm having trouble adjusting the thickness of the pie chart. Despite using the innerRadius property, it's not producing the desired ...

Adding CSS styles on hover with Jquery append

Currently, I am attempting to use jQuery to append hover CSS styles to buttons. While I have been successful in applying the desired styles upon hovering over the button, the issue arises when the mouse moves away - the styles remain. Here's the code ...

Adjust the state based on the event in ReactJs

I have the following code snippet in a React JS application: const items = [ { value: "A", label: "A" }, { value: "B", label: "B" }, { value: "C", label: "C" }, { value: "D", label: "D" }, { value: " ...

Generating unique identifiers for jQuery carousel

<div id="container_01"> <div class="pikachoose"> <ul id="pikame" class="jcarousel-skin-pika"> <li> <img id="main_photo" name="main_photo" src="image.jpg" width="520" height="380" class="del ...

Trigger file upload window to open upon clicking a div using jQuery

I utilize (CSS 2.1 and jQuery) to customize file inputs. Everything is working well up until now. Check out this example: File Input Demo If you are using Firefox, everything is functioning properly. However, with Chrome, there seems to be an issue se ...

Tips for centering a paragraph vertically within a div element

I'm struggling to achieve automatic vertical alignment for this. While I can manually center it using padding-bottom, I prefer a way to position it vertically on its own. How can I accomplish this while retaining the display: inline-block feature? &l ...

Tips on toggling between slides with Bootstrap Carousel

I am in the process of designing a portfolio website and have encountered a challenge. I want to divide it into two sections - a brief introduction and a carousel for showcasing projects. While I have managed to set up both sections, I'm facing an iss ...

How can we determine if the submit function in HTML5 is returning an error or not?

I have implemented HTML5 validation on my website. <form class="" id="myForm" method="post" action="#" > <input type="text" required /> <input type="submit" /> </form> <div> <input type="button" id="myButton" /></di ...

No space left around the image's border

Whenever I apply a border to an image, it comes with a margin and the image itself receives white padding. How can I remove the margin from the border? This is how I currently have it: border: 1px solid gray; ...

Is there a way to prevent Express.js from triggering a file download in the browser?

I am attempting to preview a Word document file in the browser using an iframe: <iframe style="float:right;" src="/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe> (Fo ...