The alignment of Bootstrap table headers in a Vue.js component needs adjusting for better display

Is there a way to ensure proper alignment of headers and column bodies in my Vue.js DataGrid component when utilizing the vuedraggable package for column reordering?

Below is the code snippet for my DataGrid.vue component:

<template>
  <div class="table-responsive">
    <table class="table table-striped table-hover" v-if="selectedColumns.length > 0">
      <thead>
        <draggable :list="selectedColumns" group="columns" @end="onEnd">
          <th v-for="(column, index) in selectedColumns" :key="index"&lt;>{{ column }}</th>
        </draggable>
      </thead>
      <tbody>
        <draggable v-model="mergedData" group="rows">
          <tr v-for="(data, index) in mergedData" :key="index">
            <td v-for="(column, index) in selectedColumns" :key="index">
              {{ data[column.toLowerCase().replace(' ', '_')] !== undefined ? data[column.toLowerCase().replace(' ', '_')] : 'N/A' }}
            </td>
          </tr>
        </draggable>
      </tbody>
    </table>
  </div>
</template>

<script>
import draggable from 'vuedraggable';

export default {
  name: 'DataGrid',
  components: {
    draggable,
  },
  props: {
    selectedColumns: {
      type: Array,
      required: true,
    },
    mergedData: {
      type: Array,
      required: true,
    },
  },
  methods: {
    onEnd(event) {
      const oldIndex = event.oldIndex;
      const newIndex = event.newIndex;
      this.selectedColumns.splice(newIndex, 0, this.selectedColumns.splice(oldIndex, 1)[0]);
    },
  },
};
</script>

<style scoped>
/* Include any customized styles here */
</style>

I have attempted wrapping the table element with a div having the table-responsive class, but the alignment of headers and column bodies remains incorrect. How can I rectify the alignment issue while preserving responsiveness and drag functionality?

Here is how my current table appears:

Answer №1

I managed to resolve the problem,

As I was utilizing the vuedraggable library, it ended up wrapping my <th>...</th> with an additional <div> element dynamically.

This is how it looked originally,

<thead>
 <tr>
  <div>
   <th></th> 
   ...
   ...
   ...
   <th></th>
  </div>
 </tr>
</thead>

The <td> elements were also wrapped inside a <div>.

<tbody>
 <div>
  <tr>
   <td></td>
   ...
   ...
   ...
   <td></td>
  </tr>
 </div>
</tbody>

To fix this issue, I included the following CSS in my vuejs component,

tbody > div:first-child {
    display: contents!important;
}
thead tr > div:first-child {
  display: contents!important;
}

This adjustment resolved the alignment problem of my header and column content without affecting the dragging functionality.

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

Bootstrap 5 ACF Repeater Accordion

Currently, I am working on using an ACF repeater field to create an FAQ accordion utilizing Bootstrap 5 with a straightforward question and answer format. Although I am able to display the results, when clicking on the accordion expander, all fields open i ...

What are the different kinds of properties that can be used in Vue.js

When working with Javascript, I can create arrays that hold different types of data elements like: var ex = ['name', 12, true]; console.log(ex); In Vue JS, when defining props for a component within a single file template, I have the option to ...

Challenges with parsing JSON using jQuery

I am attempting to retrieve data from a page that returns JSON in order to store it in an array. The current code is functional, but I am encountering difficulties when trying to pass the variable (which should contain the content) into the jQuery.parseJSO ...

Ways to boost an array index in JavaScript

I recently developed a JavaScript function that involves defining an array and then appending the values of that array to an HTML table. However, I am facing an issue with increasing the array index dynamically. <script src="https://cdnjs.cloudflare. ...

Employing state management in React to toggle the sidebar

A working example of a sidebar that can be toggled to open/close using CSS, HTML and JavaScript is available. Link to the Example The goal is to convert this example to React by utilizing states instead of adding/removing CSS classes. To ensure the side ...

Programmatically select rows in multiple mode using Primevue Datatable

Currently, I am utilizing the PrimeVue Datatable which includes multiple selection checkboxes. One key feature that I aim to implement is the ability to add a new row to the table and have it automatically selected upon addition. However, I am encounterin ...

Creating unique URLs for websites can be accomplished by following these steps:

I am in the process of developing a website where content in the main div within the body section can be replaced. However, I have realized that all content will end up on the same URL. Any suggestions on how to fix this? HTML/PHP(index.php): <htm ...

The creation of "Scoped" scss files restricts their functionality to multiple vue components rather than working on a single component

Currently, I am tackling a complex Vue project that consists of numerous components. My challenge lies in trying to incorporate some SCSS files to apply them to a specific component or route tree. I attempted using lang="scss" scoped to achieve this, but u ...

Aligning divs, prevent duplicate HTML within multiple divs

Currently, I am attempting to troubleshoot a jsfiddle issue. The main problem lies in my desire for the first two divs (with class="fbox") to be aligned next to each other on the same level. Furthermore, I am looking to enable dragging the image into the ...

Updating parent variable does not reflect changes made in child component

I need help creating custom form fields for my page. I've discovered that using props won't work to achieve this, so I'm searching for a solution to update a variable in the parent component when the child component is used. However, every t ...

Is there a way to modify the text within a "span" element that directly follows an "i" element using jQuery?

I am attempting to modify the text displayed on a button within a plugin by using jQuery. Here is the outer HTML: <button value="[[3,1,1488182400]]" data-group="2017-02-27" class="ab-hour"> <span class="ladda-label"> <i class="ab-hour ...

Working with material-design-icons offline in Vue and controlling their size

Incorporating materialdesignicons into my vue project has been a crucial aspect of my development process. import '../node_modules/@mdi/font/css/materialdesignicons.min.css'; Vue.use(Vuetify, { iconfont: 'mdi' }); I have successfully ...

The notification panel pop-up box keeps moving away from the right side

I'm currently in the process of creating a straightforward vertical notification panel, similar to the one seen on Stack Overflow. However, I've encountered an issue where the pop-up is not staying positioned correctly to the right side. It behav ...

Incorporating Vue.js - Seeking access to the latest data in my store.state through the router

I'm facing an issue with retrieving the store.state.role data in my router to determine the appropriate routes file for the application. Upon using console.log(store.state), I can see that the correct data is stored in store.state.role. However, when ...

What are the steps to creating a fading effect for an item that appears as it enters the field of view and disappears as it exits the field of view?

Implementing a fade-in effect for a button as the user scrolls down and the button comes into view, along with a fade-out effect as the user continues scrolling down and the button goes out of view. var fadeInButton = $('#fadeInButton'); ...

Positioning children within a div element

Howdy! I have a neat little setup with two divs stacked on top of each other, each containing child elements. My goal is to hide the first div and have the second div seamlessly take its place while keeping the child elements in their original position. C ...

What is causing so many issues when this component is integrated? (the scope of issues will be detailed later on)

I have the following 3 components: news-feed.component user-activity-item.component user-activity-list.component Both user-activity components are located within a subdirectory of the news-feed component. Additionally, the user-activity-item is just a ...

Arranging text within a td cell

This is what I currently have: <tr> <td colspan="4" style="font-size:7pt; font-color:red; font-weight: bold;"> PLEASE NOTE: SPECIFY THE ARTICLE IN AS MUCH DETAIL AS POSSIBLE </td> </tr> However, the text does not a ...

Incorporating Scatter Dots into a Horizontal Stacked Bar Chart using Chart.js

My horizontal stacked bar chart is not displaying pink scatter dots based on the right y axis numbers. I need help figuring out what I am doing wrong. When I change the chart to a normal bar instead of horizontal, the dots appear. However, I require them ...

When I implement inline CSS, everything works smoothly. However, when I try to use the same styles in an external

I am facing an issue with CSS. I have created an HTML page and added some padding and margin properties using inline CSS, which is working fine. However, when I try to add the same properties in my external CSS file, they are not taking effect. Here is my ...