mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
81 lines
1.3 KiB
Markdown
81 lines
1.3 KiB
Markdown
# Custom Style
|
|
|
|
Row: Set `row-class-name` prop to assign a class name to certain rows.
|
|
|
|
Column: Set `className` property on column object to assign a class name to a certain column.
|
|
|
|
```html
|
|
<n-data-table
|
|
ref="table"
|
|
:columns="columns"
|
|
:data="data"
|
|
:row-class-name="rowClassName"
|
|
/>
|
|
```
|
|
|
|
```js
|
|
const data = [
|
|
{
|
|
key: 0,
|
|
name: 'John Brown',
|
|
age: 32,
|
|
address: 'New York No. 1 Lake Park'
|
|
},
|
|
{
|
|
key: 1,
|
|
name: 'Jim Green',
|
|
age: 42,
|
|
address: 'London No. 1 Lake Park'
|
|
},
|
|
{
|
|
key: 2,
|
|
name: 'Joe Black',
|
|
age: 32,
|
|
address: 'Sidney No. 1 Lake Park'
|
|
}
|
|
]
|
|
|
|
export default {
|
|
data () {
|
|
return {
|
|
data: data,
|
|
columns: [
|
|
{
|
|
title: 'Name',
|
|
key: 'name'
|
|
},
|
|
{
|
|
title: 'Age',
|
|
key: 'age',
|
|
className: 'age'
|
|
},
|
|
{
|
|
title: 'Address',
|
|
key: 'address'
|
|
}
|
|
]
|
|
}
|
|
},
|
|
methods: {
|
|
rowClassName (row, index) {
|
|
if (row.age > 32) {
|
|
return 'too-old'
|
|
}
|
|
return null
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
```css
|
|
::v-deep(.too-old td) {
|
|
color: rgba(255, 0, 0, 0.75) !important;
|
|
}
|
|
::v-deep(.age) {
|
|
color: rgba(0, 128, 0, 0.75) !important;
|
|
}
|
|
::v-deep(.too-old .age) {
|
|
color: rgba(0, 0, 128, 0.75) !important;
|
|
}
|
|
```
|