How do I customize the appearance of an Element-UI data table in Vue?

I'm struggling to customize the color of an Element UI datatable in my project. I've tried several approaches, but so far, nothing has worked. Here is the code I am currently using:

<template>
  <el-table
    :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
    style="width: 100%">
    <el-table-column
      label="Date"
      prop="date">
    </el-table-column>
    <el-table-column
      label="Name"
      prop="name">
    </el-table-column>
    <el-table-column
      align="right">
      <template slot="header" slot-scope="scope">
        <el-input
          v-model="search"
          size="mini"
          placeholder="Type to search"/>
      </template>
      <template slot="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">Edit</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<style>

.thead {
  color: red;
}
.el-table thead {
  color: red;
}

</style>

<script>

export default {

  props:{


  },

  data() {
      return {
        tableData: [{
          date: '2016-05-03',
          name: 'Tom',
          address: 'No. 189, Grove St, Los Angeles'
        }, {
          date: '2016-05-02',
          name: 'John',
          address: 'No. 189, Grove St, Los Angeles'
        }, {
          date: '2016-05-04',
          name: 'Morgan',
          address: 'No. 189, Grove St, Los Angeles'
        }, {
          date: '2016-05-01',
          name: 'Jessy',
          address: 'No. 189, Grove St, Los Angeles'
        }],

        search: '',
      }
    },

    methods: {
      handleEdit(index, row) {
        console.log(index, row.name);
      },
      handleDelete(index, row) {
        console.log(index, row.name);
      }
    },
  

}

</script>

The changes I've made don't seem to be affecting the table at all. I've experimented with properties like background-color, and classes such as .el-table, but to no avail. Any advice on how I can achieve this customization would be greatly appreciated.

Answer №1

The reason setting the table background color did not work is because the default row background color takes precedence. The datatable offers various properties for styling, or you can directly target the row using CSS. In both cases, using the !important modifier is necessary to override the default styles:

Option 1: Utilizing a property like row-class-name:

<el-table
  row-class-name="myrow"
>
.myrow {
  background-color: red !important;
}

Option 2: Adjusting the CSS directly with tr (or td, th, etc.)

.el-table tr {
  background-color: red !important;
}

(Alternatively, you can utilize a more specific selector to avoid the use of !important when making direct modifications, if that is important to you.)

Answer №2

experiment with deep selector

.variableName>>>.el-table{
  background-color: red !important;
}
.variableName/deep/.el-table{
  background-color: red !important;
}

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 creating a unique custom UI headline using ReactJS, CSS, and bootstrap

Looking to create a design that is responsive in ReactJS using Bootstrap or CSS if needed. I need assistance with placing separators between columns and ensuring the values of each label are aligned in the same column but on the next line. The layout shoul ...

A guide on personalizing HTML for Django forms

I have implemented an HTML template on my website and need to capture information for my Django backend. Specifically, I am trying to extract the email address from this section of code: <input type="text" placeholder="Email" value="" style="height: 30 ...

Tips to avoid the page from scrolling to the top when the menu is opened

Whenever a user taps the menu button on the page, a full-page menu opens. However, there is an issue - the main content page automatically scrolls to the top. Can you provide suggestions on how to prevent this from happening? I have already looked into a s ...

Ways to stop user authentication in Firebase/Vue.js PRIOR to email verification

I am currently working on a Vue.js and Firebase authentication interface with an email verification feature. The setup is such that the user cannot log in until they click the verification link sent to the email address provided during the login process. ...

Tips for ensuring an image fits perfectly within a MUI grid

I am currently working on an application that involves a collection of cards. My tech stack includes React and MUI v5. One issue I've been facing is with the grid layout, specifically in trying to keep the image size consistent within the grid item. ...

Leveraging the power of Vue.js and Vuex to extract information from a v-for loop and retrieve additional data

Currently, I am engrossed in my capstone project at our school. My tech stack includes nuxt, vue, vuex, and vuetify for the client-side rendering and express for server-side rendering. Within my code, I am aiming to retrieve data from a v-for loop and then ...

Enhancing event data in Vue.js: A comprehensive guide

I'm currently working on a scenario where I have a Parent.vue component that sends an object to a Child component and receives back the updated item periodically through this.$emit('updateItem', item). <template> <div> < ...

Looking for PHP templating solutions for creating stylish headers and footers on your

I am in the process of creating a website with various pages dedicated to About information, Projects, Events, and more. One issue I am facing is how to seamlessly include my navigation bar, header, and footer across all HTML files without duplicating the ...

Utilize flex to position content at the bottom

My layout features a fixed header and footer, positioned at the top and bottom respectively. The content section in between fills the remaining space, with a scrollbar available if the content extends beyond the area. <div id="app"> <d ...

The Art of Div Switching: Unveiling the Strategies

I have a question regarding my website. I have been working on it for some time now, but I have encountered a challenge that I am struggling to overcome. After much consideration, I am unsure of the best approach to take. The issue at hand is that I have ...

Set the background color of the container row to extend the full width, encompassing

I am working on a grid container and I want to change the background color of the second row within it. Check out my Fiddle This is the HTML markup: <div class="totalContainer totalContainer__space"> <div class="totalContainer__ ...

How to conditionally enclose a group of components in a div using VueJS

I am working with a ref variable that has a specific structure: [ { "row": 1, "column": 1 }, { "row": 1, "column": 2 }, { "row": 1, "column": 3 }, { "row": 1, "column": 4 }, { ...

Ensure consistency in the heights of div elements, even when the images contained within have varying heights

I created a bootstrap webpage with a row of DIVs, each containing an image. As I resize the browser window, I noticed that the height of the first two DIVs remains consistent, but the third div's height varies because the image is only 50 pixels high. ...

Tips for designing a responsive element with a repeating border

Desired Design: Create a dotted border on top of each li-element Adjust the size of the dots and spacing between them using CSS or image/SVG manipulation Make the width of the ul responsive for varying border widths Ensure that dots are not partially dis ...

Handling exceptions in the event that the backend URL resource cannot be accessed

I'm facing an issue with my Vue.js single file component where I am trying to catch exceptions when the URL requested by axios.post is unreachable. I have encapsulated the entire code in a try block, but for some reason, the alert in the catch block i ...

Modifying the order of Vuetify CSS in webpack build process

While developing a web app using Vue (3.1.3) and Vuetify (1.3.8), everything appeared to be working fine initially. However, when I proceeded with the production build, I noticed that Vue was somehow changing the order of CSS. The issue specifically revol ...

Using Javascript and CSS to Float DIV Elements

Recently, I've been working on a small algorithm that adds a special class to an element when the mouse reaches the halfway point or beyond on the X-axis of the browser. I also have a screenshot that demonstrates where this application will be utiliz ...

Vue computed and watch will not be triggered when there are changes to nested properties

When a computed method triggers is if one of the main property declared inside the data(){} However, it will not trigger on nested property changes even when using watch deep. myApp.component("editfeemodal", { props: ['feedetail'], ...

Error in jQuery submenu positioning issue

I am attempting to design a menu that opens when the parent element is clicked and closes when the mouse leaves the previously opened one. It should operate from left to right. Here is an example: <ul class="menuFirst"> <li><im ...

Restricting the scope of reactivity in a VueJS data store

Goal: I am attempting to create an array of objects retrieved through an API call. After making the initial API call and receiving a single object, I want to store that result and then make another call without updating the original stored object. Challen ...