Row in Vue Treegrid component
16 Mar 20234 minutes to read
The row represents record details fetched from data source.
Customize rows
You can customize the appearance of a row by using the rowDataBound
event.
The rowDataBound
event triggers for every row. In the event handler, you can get the
RowDataBoundEventArgs
that contains details of the row.
<template>
<div id="app">
<ejs-treegrid :dataSource="data" :treeColumnIndex='1' childMapping='subtasks' height='315px' :rowDataBound='rowDataBound'>
<e-columns>
<e-column field='taskID' headerText='Task ID' textAlign='Right' width='90'></e-column>
<e-column field='taskName' headerText='Task Name' width='180'></e-column>
<e-column field='startDate' headerText=' Start Date' textAlign='Right' format='yMd' type='date' width='90'></e-column>
<e-column field='duration' headerText='Duration' textAlign='Right' width='80'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import Vue from "vue";
import { TreeGridPlugin } from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from "./datasource.js";
Vue.use(TreeGridPlugin);
export default {
data () {
return {
data: sampleData,
};
},
methods:{
rowDataBound: function(args) {
if (args.data['duration'] == 0 ) {
args.row.style.background= '#336c12';
} else if (args.data['duration'] < 3) {
args.row.style.background= '#7b2b1d';
}
}
}
}
</script>
Styling alternate rows
You can change the treegrid’s alternative rows’ background color by overriding the .e-altrow
class.
.e-treegrid .e-altrow {
background-color: #fafafa;
}
Please refer to the following example.
<template>
<div id="app">
<ejs-treegrid :dataSource="data" :treeColumnIndex='1' childMapping='subtasks' height='315px'>
<e-columns>
<e-column field='taskID' headerText='Task ID' textAlign='Right' width='90'></e-column>
<e-column field='taskName' headerText='Task Name' width='180'></e-column>
<e-column field='startDate' headerText=' Start Date' textAlign='Right' format='yMd' type='date' width='90'></e-column>
<e-column field='duration' headerText='Duration' textAlign='Right' width='80'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import Vue from "vue";
import { TreeGridPlugin } from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from "./datasource.js";
Vue.use(TreeGridPlugin);
export default {
data () {
return {
data: sampleData,
};
},
}
</script>
<style>
.e-grid .e-altrow {
background-color: #fafafa;
}
</style>