Issue with Datatables Layout - Button and Dropdown Alignment

This is my current layout in the image below. I have annotated the picture to demonstrate the desired layout changes, but I am struggling to implement them. Everything below the "New Post" button (buttons, pagination, search, table, etc.) is generated by DATATABLES. I attempted to manipulate the DOM without success.

The desired layout can be viewed here.

$(document).ready(function() {
  $('#table-mh-admin-blog').DataTable({
    dom: '<Blfr<t>ipl>',
    buttons: [
      'copy', 'excel', 'pdf', 'print'
    ],
    select: true,
    "order": [
      [4, "asc"]
    ],
    stateSave: true,
  });
});
<div class="row ">
  <h1>All Posts </h1>

  <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_create/"><i class="fa fa-plus"></i> New Post</a>
  <div>

    <table id="table-mh-admin-blog" class="table table-condensed table-bordered table-striped table-hover" width="100%">
      <thead>
        <tr>
          <th>Category</th>
          <th>Author</th>
          <th>Title / Post</th>
          <th>Created</th>
          <th>Updated</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Associations and Organizations</td>
          <td>administrator</td>
          <td>
            <p> fffff</p>
            <p>
              fffff</td>
          </p>
          <td>2018-09-21 04:06:27</td>
          <td>
            N/A </td>
          <td style="white-space:nowrap;">
            <a class="btn btn-success btn-sm" href="/Blog_admin/blog_update/slug/fffff"><i class="fa fa-edit"></i></a>
            <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_view_single/fffff"><i class="fa fa-eye"></i></a>
            <a href="https://www.example.net/Blog_admin/blog_delete/id/190" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-alt"></i></a>
          </td>

        </tr>
        <tr>
          <td>24354234234</td>
          <td>administrator</td>
          <td>
            <p> test1</p>
            <p>

              asdasdasdasdasd richard testrtghfghf asdasd


          </td>
          <td>2018-09-29 05:37:09</td>
          <td>
            2018-10-08 22:48:30 </td>
          <td style="white-space:nowrap;">
            <a class="btn btn-success btn-sm" href="/Blog_admin/blog_update/slug/test1"><i class="fa fa-edit"></i></a>
            <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_view_single/test1"><i class="fa fa-eye"></i></a>
            <a href="https://www.example.net/Blog_admin/blog_delete/id/197" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-alt"></i></a>
          </td>

        </tr>
        <tr>
          <td>24354234234</td>
          <td>administrator</td>
          <td>
            <p> xxxxxxxxxxxxxxx</p>
            <p>
          </td>
          <td>2018-10-06 07:12:59</td>
          <td>
            2018-10-08 22:37:32 </td>
          <td style="white-space:nowrap;">
            <a class="btn btn-success btn-sm" href="/Blog_admin/blog_update/slug/xxxxxxxxxxxxxxx"><i class="fa fa-edit"></i></a>
            <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_view_single/xxxxxxxxxxxxxxx"><i class="fa fa-eye"></i></a>
            <a href="https://www.example.net/Blog_admin/blog_delete/id/198" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-alt"></i></a>
          </td>

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

</div>

<div class="row">
  <div class="pagination-links">

  </div>
</div>
<!-- end of row -->

Any assistance would be greatly appreciated.

Answer №1

Ensure that you reference the datatable in your HTML code. It appears to have been overlooked, so including it is crucial for achieving the desired outcome.

$(document).ready(function() {
  $('#table-mh-admin-blog').DataTable({
    dom: '<Blfr<t>ipl>',
    buttons: [
      'copy', 'excel', 'pdf', 'print'
    ],
    select: true,
    "order": [
      [4, "asc"]
    ],
    stateSave: true,
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
 <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<div class="row ">
  <h1>All Posts </h1>

  <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_create/"><i class="fa fa-plus"></i> New Post</a>
  <div>

    <table id="table-mh-admin-blog"  width="100%">
      <thead>
        <tr>
          <th>Category</th>
          <th>Author</th>
          <th>Title / Post</th>
          <th>Created</th>
          <th>Updated</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Associations and Organizations</td>
          <td>administrator</td>
          <td>
            <p> fffff</p>
            <p>
              fffff</td>
          </p>
          <td>2018-09-21 04:06:27</td>
          <td>
            N/A </td>
          <td style="white-space:nowrap;">
            <a class="btn btn-success btn-sm" href="/Blog_admin/blog_update/slug/fffff"><i class="fa fa-edit"></i></a>
            <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_view_single/fffff"><i class="fa fa-eye"></i></a>
            <a href="https://www.example.net/Blog_admin/blog_delete/id/190" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-alt"></i></a>
          </td>

        </tr>
        <tr>
          <td>24354234234</td>
          <td>administrator</td>
          <td>
            <p> test1</p>
            <p>

              asdasdasdasdasd richard testrtghfghf asdasd


          </td>
          </p>
          <td>2018-09-29 05:37:09</td>
          <td>
            2018-10-08 22:48:30 </td>
          <td style="white-space:nowrap;">
            <a class="btn btn-success btn-sm" href="/Blog_admin/blog_update/slug/test1"><i class="fa fa-edit"></i></a>
            <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_view_single/test1"><i class="fa fa-eye"></i></a>
            <a href="https://www.example.net/Blog_admin/blog_delete/id/197" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-alt"></i></a>
          </td>

        </tr>
        <tr>
          <td>24354234234</td>
          <td>administrator</td>
          <td>
            <p> xxxxxxxxxxxxxxx</p>
            <p>
          </td>
          </p>
          <td>2018-10-06 07:12:59</td>
          <td>
            2018-10-08 22:37:32 </td>
          <td style="white-space:nowrap;">
            <a class="btn btn-success btn-sm" href="/Blog_admin/blog_update/slug/xxxxxxxxxxxxxxx"><i class="fa fa-edit"></i></a>
            <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_view_single/xxxxxxxxxxxxxxx"><i class="fa fa-eye"></i></a>
            <a href="https://www.example.net/Blog_admin/blog_delete/id/198" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?')"><i class="fa fa-trash-alt"></i></a>
          </td>

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

</div>

<div class="row">
  <div class="pagination-links">

  </div>
</div>


 
<!-- end of row -->

Answer №2

Learn how to easily and efficiently utilize datatable by incorporating the following concept into your code structure. If DataTable is failing to run due to missing jQuery, you may encounter issues.

$(document).ready(function() {

  var dataSet = [
    // Data entries here...
  ];

  var columnDefs = [{
    title: "Name"
  }, {
    title: "Position"
  }, {
    title: "Office"
  }, {
    title: "Extn."
  }, {
    title: "Start date"
  }, {
    title: "Salary"
  }];

  var myTable;

  myTable = $('#example').DataTable({
    "sPaginationType": "full_numbers",
    data: dataSet,
    columns: columnDefs,
    dom: 'Bfrtip',        // Button container
          select: 'single',
          responsive: true,
          altEditor: true,
          // Enable altEditor
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<div class="row ">
  <h1>All Posts </h1>

  <a class="btn btn-primary btn-sm" href="https://www.example.net/Blog_admin/blog_create/"><i class="fa fa-plus"></i> New Post</a>
  <div>

    <div class="container">
  <table cellpadding="0" cellspacing="0" border="0" class="dataTable table table-striped" id="example">

  </table>
</div>
<!-- end of row -->

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

The jQuery.one() function fires off twice

Why am I experiencing a strange issue where the event bound with jQuery.one() gets triggered twice when I hit Enter in the input and then click outside the input within the same second? I thought that one() was meant to trigger at most once! $('.list& ...

Setting a button next to an input field in Bootstrap 4: A step-by-step guide

I have a form group with a label and input field. My goal is to position the button next to the input field on the same line. Here's an example of my code: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstra ...

Implement a collapsible navbar using bootstrap

To create a responsive navbar that collapses into a burger menu when clicked, you can use the following HTML structure: <body> <header id="nav-wrapper"> <img id="logo" src="images/event-logo.png" /> <nav class="n ...

Fetching external data in a Cordova application from a remote server

I have encountered multiple questions similar to mine, but none of them have been able to solve my issue. Currently, I am developing a Cordova app for testing on Android and iOS platforms. My goal is to retrieve data in JSON format from my webserver using ...

When attempting to send JSON data to the server using a .ajax() post request, it seems to only be

I am encountering an issue where I am attempting to insert a JSON string into the database by making a call to a web service through an AJAX request. Strangely, when I debug the code using Chrome debugger, the string gets successfully inserted into the DB. ...

What is the best way to retrieve the ID of the list item that has been clicked during a button event?

How can I use jQuery to get the ID of a selected list item when clicking a button in my HTML code? <ul id="nav"> <li><a href="#" rel="css/default.css" id="default" > <div class="r1"></div> </a>< ...

Troubleshooting: JQuery - Applying CSS to dynamically generated elements

I used JQuery to dynamically generate a table, but I'm having trouble applying CSS to the columns. You can see an example at this Codepen link here. Specifically, I need to set the width of the first column to 100px. Could someone please assist me wi ...

Gin and Golang: Implementing HTML files with CSS styling

I am still learning English, so please bear with me :) My issue is that when using Gin to load HTML, my HTML file contains an import (/stylesheet/index.css), but when I run my app with Gin, it gives an alert that the stylesheet file could not be loaded. ...

Reinitialize Yii2 form with jQuery without triggering mandatory data warning

I've tried multiple ways to reset the form, but none seem to work correctly. In Yii2, I keep getting a "data required" error even after clearing a field, and one of them doesn't even clear. Here is the Yii2 action function: public function acti ...

Balanced Columns with Background Extending Beyond Half of the Page

If you're looking for the final code, it can be found here: http://jsfiddle.net/asaxdq6p/6/ I am attempting to create an effect similar to this image: To achieve this, I am using the Equal Height Columns with Cross-Browser CSS trick as described in ...

Click handler fails to trigger on dynamically rendered elements through Ajax Callback, limited to Safari browser only

I'm facing an issue with getting a feature to work on Safari and iOS devices, even though it works perfectly on Firefox, Chrome, Edge, and IE. The problem arises with an input field on the page that sends user input to the server and updates the DOM ...

Is there a way to isolate the highlighted text from an HTML document?

I am in search of a solution to extract all the bold snippets within the content of an HTML document. The task needs to be performed on the server side using Java, rather than on the client-side browser. The text appearing as bold on the page may be due t ...

Tips for resolving the "Forbidden compound class names" error that occurs when trying to select an input field

As a newcomer to selenium, I am eager to start testing the login page. The text field below is where I need to input the username: <div class="WODM WNDM" data-automation-id="userName"> <div class="gwt-Label WBEM">Email Address</div><i ...

Implementing ajax for developing an authentication application, however, there seems to be a missing return statement

When I click "post", the response that I am getting from Firefox is: Password Username: k Source: username=k&password= The print received from the PHP won't display in the #errorshow div. Here is my code (HTML) <!DOCTYPE HTML PUBLIC "-//W ...

"Troubleshooting an issue with mod_rewrite affecting the functionality of an ajax

The issue arises when the ajax request is not triggered after the URL has been rewritten using mod_rewrite. However, by simply removing the trailing slash from the link, the functionality works as expected. For example: It works with these URLs http:// ...

Displaying JavaScript array contents in an HTML page without using the .innerHTML property

As someone new to the world of JavaScript and web development, I find myself faced with a challenge. I want to showcase the contents of two different JavaScript arrays in an HTML format. However, my research has led me to believe that utilizing .innerHTML ...

using jQuery to disable textarea input

I have this HTML code and I am using jQuery: <div><textarea style="height: 150px; width: 250px" name="myName" id="myId" class="text ui-widget-content ui-corner-all" > </textarea></div> Currently, I validate this field after the su ...

Obtain the value of a dynamically selected option

I am facing an issue with my select options where I want the input field to be automatically filled with the 'data-place' value of the selected option whenever it changes. This includes a few dynamic select options. $(function() { // Hand ...

Having trouble with Safari on your iPhone? Seeing image outlines peeking through radius borders?

Has anyone encountered a similar issue before? I'm experiencing this problem specifically on Safari for iPhone. Problem: https://i.sstatic.net/ffqWz.jpg Solution: https://i.sstatic.net/z1bUB.png Below is the HTML code snippet: <div class="row"& ...

How come the html element doesn't have a default height of 100%?

Is there a reason why the html element is not automatically set at 100% height by default? Can you think of any scenarios where having it take up less than the full height of the window would be beneficial? html { height: 100%; } [Update] I modified th ...