I want to set the row background color based on an item's data field.
The only way to do that right now is to manually set the background for each column slot.
Adding a row-class
and/or row-style
function could make it easy for user to have per-row control.
Example:
export default {
data() {
return {
rowClass: ({ item }) => this.getColor(item)
};
},
methods: {
getColor(calories) {
if (calories > 400) return "red";
else if (calories > 200) return "orange";
else return "green";
}
}
};
Use the item
slot
Doesn't that require the column rendering functionality to be provided in the item
slot?
What column rendering functionality? It's like it was in 1.x, you bring your own tr/td
I would like to resurrect this issue...
In my case, I want to allow users to change the columns' positions, while also applying a custom class to rows depending on a property. If I redefine the entire row using theitem
slot, the table looses the ability to properly react to changes in the headers
prop, i.e. when headers
is replaced with a new array sorted differently, the headers and the cells will not match anymore.
Besides, having to redefine the way every column is rendered just to modify a small property of the row (which, I believe, is what @dasDaniel was referring to) is a complete overkill.
I came across this when trying to reduce the size of the rows in a v-data-table, but "dense" was simply too... dense. Ended up adding a new CSS file and importing it:
In the Vue file add "dense" to v-data-table and import the customizing CSS:
<style scoped>
@import "../../assets/css/overview.css";
</style>
CSS:
.theme--light.v-data-table--dense tr {
height: 30px;
}
Individual cell styling is possible with a Bootstrap Vue table though.
I agree with this being an issue - I need to adjust just the row css class (depending on an items value), and it appears the only solution is to switch to using item slots and defining all the table content myself, which is overkill.
@gatkinsNZ see https://github.com/vuetifyjs/vuetify/issues/8643
BTW, propery item-class does not work
In documentation https://vuetifyjs.com/en/components/data-tables/#data-tables
Property on supplied items that contains item's row class or function that takes an item as an argument and returns the class of corresponding row
We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression or reach out to us in our Discord community.
Thank you for your contribution and interest in improving Vuetify.
Most helpful comment
I agree with this being an issue - I need to adjust just the row css class (depending on an items value), and it appears the only solution is to switch to using item slots and defining all the table content myself, which is overkill.