Instructions on integrating a column of buttons into a Bootstrap table containing information retrieved from a MySQL database

My bootstrap table is currently displaying data that is loaded from a MySQL database. I am looking to enhance it by adding a column with buttons, similar to the layout shown in this image.

https://i.stack.imgur.com/8fWfR.png

However, I am facing some difficulties in incorporating buttons into my script. It's easy when manually creating a table, like this:

<td>
<a href="#" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> Edit </a>
<a href="#" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> Delete </a>
</td>

But when populating the table with data from the database, the process becomes more complex. This is a snippet of my code:

<table  id="table"
   data-show-columns="true"
   data-height="460">
</table>

Here is the script for loading the data (Please note that I have omitted the list.php file as it primarily deals with PHP scripts for connecting to the database and executing SELECT queries):

<script type="text/javascript">

   var $table = $('#table');
         $table.bootstrapTable({
            url: 'include/list.php',
            search: true,
            pagination: true,
            buttonsClass: 'primary',
            showFooter: true,
            minimumCountColumns: 2,
            columns: [{
                field: 'id',
                title: 'ID',
                sortable: true,
            },{
                field: 'creation_date',
                title: 'Date',
                sortable: true,
            },{
                field: 'latitude',
                title: 'Latitude',
                sortable: true,

            },  ],

         });

</script>

Answer №1

Everything you need is right here

$('#table tbody tr').append('<td><a href="#" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> Edit </a><a href="#" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> Delete </a></td>');

Answer №2

After tackling this issue head-on, I managed to resolve it using the approach outlined below:

    <?php
      include_once 'include/connect_db.php';

      $query = "SELECT * FROM base;";
      $result = execute_query($query);

      $list = array();
      while ($b = mysqli_fetch_array($result)) {
        $list[] = $b;
      }
    ?>

<table id="table-b" class="table table-striped projects">
<thead>
  <tr>
    <th style="width: 1%">#</th>
    <th style="width: 10%">ID de base/th>
    <th>Fecha de registro</th>
    <th>Latitud</th>
    <th>Longitud</th>
    <th style="width: 20%"></th>
  </tr>
</thead>
<tbody>
  <?php foreach ($list as $row):?>
  <tr>
    <td><?php echo $row['ID'];?></td>
    <td><?php echo $row['creation_date'];?></td>
    <td><?php echo $row['latitude'];?></td>
    <td><?php echo $row['longitude'];?></td>
    <td>
      <a href="#" class="btn btn-info btn-xs"><i class="fa fa-pencil"></i> Edit </a>
      <a href="#" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> Delete </a>
    </td>
  </tr>
  <?php endforeach;?>
</tbody>
</table>


        <script>
             $(document).ready(function(){
                      $('#table-b').dataTable({
                      "sPaginationType":"full_numbers",
                      "aaSorting":[[0, "asc"]],
                      "bJQueryUI":true
                      });

                      hideLoading();

             });
        </script>

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 implementing styling in a material table within a reactjs application

Is there a different way to set the display property to inline-block since cellStyle doesn't seem to recognize it? How can I adjust the width of a specific column, let's say with the name title, without affecting the width of all other co ...

Discover how to shallow test for the presence of a wrapped component using Jest and Enzyme

Currently, I am in the process of testing a component that dynamically renders another wrapped component based on certain conditions. My testing tools include enzyme and jest, with the root component being rendered using the shallow() method. The main chal ...

Using React with Typescript to display components generated from the `map` function

In my scenario, I have retrieved data from a JSON file and am also utilizing a utility function that selects 5 random entities from an object Array. This particular array contains 30 entities. Struggling with displaying the 5 random jockeys stored in the ...

Ensure that the modal remains open in the event of a triggered keydown action, preventing it from automatically closing

I am currently toggling the visibility of some modals by adjusting their CSS properties. I would like them to remain displayed until there is no user interaction for a period of 3 seconds. Is there a way to achieve this using JavaScript? Preferably with Vu ...

The issue arises with loading data from the server due to lack of definition of Mongo

I am experiencing a console bug and need assistance. It seems that there is an issue with loading data from the server as I am getting an error stating "Mongo is not defined." C:\Users\Robert\Desktop\FINISH\node_modules\mongod ...

When a user clicks on an anchor tag in a React component, the input element will automatically receive

I am currently working with two components: Within my parent component, I have the following set up: // Initialize focus object as false // Import Child Component and React libraries const parent = React.createClass({ getInitialState: function() { ...

Changing an array in PHP to a variable in JavaScript

I am struggling with converting a PHP array into a JavaScript variable using json_encode. When I print out my PHP variable: <?php $damage_array = $listing->tire_detail->damage_details; ?> It displays as: Array ( [lf] => 4 [rf] => 9 [lr ...

JavaScript - Executing the change event multiple times

Below is the table I am working with: <table class="table invoice-items-table"> <thead> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> & ...

Tips for using a unique format for a single field in jqGrid

My JQGRID site has table configuration set up like this: configid config rule 1. Application_name 'MyApps' 2. Max number 1,000,00 3. Application End 12/31/2012 Some cells are for numbers and others for dates. If a user wants to edit a date ce ...

Is there a way to incorporate tailwind classes into each react component when utilizing the map() function?

While working on a React Movie app, I encountered an issue with the tailwind class mx-auto. It was not applying properly to all items in the array; only the first element was affected. const MoviesList = () => { return( <div className=&a ...

How to Disable a Dynamically Generated <li> Element Using jQuery on Click Event

Script Query: Creating <li> Elements Dynamically echo '<div class="pagination"><ul>' . "\n"; // Previous Post Link. if ( get_previous_posts_link() ) { printf( '<li>%s</li>' . "\n", get_previ ...

Preventing the sidebar from overlapping with the main content in Bootstrap layout

My layout is set up as follows: Example I am encountering an issue when resizing the window, as there is overlap with the main content. Here is an example of the issue How can I prevent this overlap while still maintaining padding? Below is my HTML an ...

Dynamic bullseye displayed on a Vis.js network node

I am currently utilizing Vis.js to create network diagrams. I am interested in adding a notification feature where when an AJAX update is received for a specific node, the canvas will move that node to the center (which Vis.js can already do). Following th ...

How does the use of let versus const differ when iterating through a collection?

Utilizing Node.js (ES6) to iterate through each item in a collection like the one provided below: var statuses = [{ statusId: 1, description: 'New' }, { statusId: 2, description: 'Pending' }, { ...

Using Redis for caching in Node.js applications

As I delved into this module, I found myself pondering the use of callbacks within it. My understanding is that memory caching is designed to be speedy, providing instant results. So why introduce callbacks, which may imply a waiting period? If the resul ...

What is the best way to incorporate TypeScript variables into CSS files?

In my Angular project, I am aiming to utilize a string defined in Typescript within a CSS file. Specifically, I want to set the background image of a navbar component using a path retrieved from a database service. Although I came across suggestions to use ...

Ways to restrict user access to internal pages without login in Reactjs

I have been working on a project using Reactjs with the nextjs framework. Currently, I am focusing on implementing a login and logout module. My goal is to redirect any user attempting to access an inner page without being "logged in" to the "index/login ...

Implementing reCAPTCHA and PHP for Email Form Submission

Currently using GoDaddy as the web host for my website. Struggling to integrate reCAPTCHA into the email form on my site. I successfully pass the reCAPTCHA test, but emails are not being sent. So far, the website has been built using PHP and HTML only. ...

Looping through an array

I have created an array as shown below: iArray = [true, true, false, false, false, false, false, false, true, true, true, false, true, false, false, false, false, true] Condition check: If any value in this array is false, I will display an error messag ...

What is the process for integrating Internet Explorer 10 compatibility into a basic VueJs component?

I am facing an issue with a VueJs component that is not rendering in IE 10. Context: The Vue component I am working on is a company events list with basic filtering and sorting functionalities. Unfortunately, IE10 support is required for this project. Eve ...