Scrolling in Vue Treegrid component
16 Mar 20237 minutes to read
The scrollbar will be displayed in the treegrid when content exceeds the element width
or height
. The vertical and horizontal scrollbars will be displayed based on the following criteria:
- The vertical scrollbar appears when the total height of rows present in the treegrid exceeds its element height.
- The horizontal scrollbar appears when the sum of columns width exceeds the treegrid element width.
- The
height
andwidth
are used to set the treegrid height and width, respectively.
Set width and height
To specify the width
and height
of the scroller in the pixel, set the pixel value to a number.
<template>
<div id="app">
<ejs-treegrid :dataSource='data' childMapping='subtasks' :treeColumnIndex='1' :height='315' :width='400'>
<e-columns>
<e-column field='taskID' headerText='Task ID' width='90' textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width='180'></e-column>
<e-column field='startDate' headerText='Start Date' width='120' format="yMd" textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width='110' textAlign='Right'></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>
Responsive with parent container
Specify the width
and height
as 100%
to make the treegrid element fill its parent container.
Setting the height
to 100%
requires the treegrid parent element to have explicit height.
<template>
<div id="app">
<p class="e-text"> The parent container can be resizable by dragging the bottom-right corner.</p>
<div id='container' class='e-resizable'>
<ejs-treegrid :dataSource='data' childMapping='subtasks' height='100%' width= '100%' :treeColumnIndex='1' >
<e-columns>
<e-column field='taskID' headerText='Task ID' width='90' textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width='180'></e-column>
<e-column field='startDate' headerText='Start Date' width='120' format="yMd" textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width='110' textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</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-resizable {
resize: both;
overflow: auto;
border: 1px solid red;
padding: 10px;
height: 300px;
min-height: 250px;
min-width: 250px;
}
</style>
Scroll to selected row
You can scroll the treegrid content to the selected row position by using the rowSelected
event.
<template>
<div id="app">
<ejs-numerictextbox ref='numeric' format='N' min='0' placeholder='Enter index to select a row' width=200 :showSpinButton='false' :change='onchange'></ejs-numerictextbox>
<ejs-treegrid ref='treegrid' :dataSource='data' childMapping='subtasks' height='280' width='100%' :treeColumnIndex='1' :rowSelected='rowSelected'>
<e-columns>
<e-column field='taskID' headerText='Task ID' width='90' textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width='180'></e-column>
<e-column field='startDate' headerText='Start Date' width='120' format="yMd" textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width='110' textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import Vue from "vue";
import { TreeGridPlugin } from "@syncfusion/ej2-vue-treegrid";
import { NumericTextBoxPlugin } from "@syncfusion/ej2-vue-inputs";
import { sampleData } from "./datasource.js";
Vue.use(TreeGridPlugin);
Vue.use(NumericTextBoxPlugin);
export default {
data () {
return {
data: sampleData
};
},
methods: {
onchange: function(){
this.$refs.treegrid.selectRow(parseInt(this.$refs.numeric.getText(), 10));
}
rowSelected: function (args) {
let rowHeight = this.$refs.treegrid.getRows()[this.$refs.treegrid.getSelectedRowIndexes()[0]].scrollHeight;
this.$refs.treegrid.getContent().children[0].scrollTop = rowHeight * this.$refs.treegrid.getSelectedRowIndexes()[0];
}
}
}
</script>