2019-12-16 17:43:56 +08:00
|
|
|
# Custom Style
|
|
|
|
|
|
|
|
> Row: Set row-class-name prop with a function to assign a class name to certain rows.
|
|
|
|
> Column: Set className key to columns prop's object to assign a class name to a certain column.
|
|
|
|
|
|
|
|
```html
|
2019-12-31 21:01:24 +08:00
|
|
|
<n-data-table
|
2019-12-16 17:43:56 +08:00
|
|
|
ref="table"
|
|
|
|
:columns="columns"
|
|
|
|
:data="data"
|
|
|
|
:pagination="pagination"
|
|
|
|
:row-class-name="rowClassName"
|
|
|
|
>
|
2019-12-31 21:01:24 +08:00
|
|
|
</n-data-table>
|
2019-12-16 17:43:56 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
const data = [
|
|
|
|
{
|
|
|
|
key: "1",
|
|
|
|
name: "John Brown",
|
|
|
|
age: 32,
|
|
|
|
address: "New York No. 1 Lake Park",
|
|
|
|
tags: ["nice", "developer"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "2",
|
|
|
|
name: "Jim Green",
|
|
|
|
age: 42,
|
|
|
|
address: "London No. 1 Lake Park",
|
|
|
|
tags: ["loser"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "3",
|
|
|
|
name: "Joe Black",
|
|
|
|
age: 32,
|
|
|
|
address: "Sidney No. 1 Lake Park",
|
|
|
|
tags: ["cool", "teacher"]
|
|
|
|
}
|
|
|
|
];
|
2020-01-05 15:20:35 +08:00
|
|
|
|
2019-12-16 17:43:56 +08:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
data: data,
|
2020-01-05 15:20:35 +08:00
|
|
|
columns: [
|
2019-12-16 17:43:56 +08:00
|
|
|
{
|
|
|
|
title: "Name",
|
|
|
|
key: "name"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Age",
|
|
|
|
key: "age",
|
|
|
|
className: "age"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Address",
|
|
|
|
key: "address"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Tags",
|
|
|
|
key: "tags"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
pagination() {
|
2020-01-05 15:20:35 +08:00
|
|
|
return { total: this.data.length, limit: 10 }
|
2019-12-16 17:43:56 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-01-05 15:20:35 +08:00
|
|
|
sendMail(row) {
|
|
|
|
this.$NMessage.info("send mail to " + row.name)
|
2019-12-16 17:43:56 +08:00
|
|
|
},
|
2020-01-05 15:20:35 +08:00
|
|
|
rowClassName(row, index) {
|
|
|
|
if (row.age > 32) {
|
|
|
|
return "too-old"
|
2019-12-16 17:43:56 +08:00
|
|
|
}
|
2020-01-05 15:20:35 +08:00
|
|
|
return null
|
2019-12-16 17:43:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
```css
|
|
|
|
/deep/ .too-old {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
/deep/ .age {
|
|
|
|
background: skyblue;
|
|
|
|
}
|
|
|
|
```
|