Having trouble getting help?
Contact Support
Contact Support
Indent in Vue Treegrid component
11 Jun 20249 minutes to read
The Indent and Outdent feature will help to change the hierarchy level of rows in tree grid. The indent action moves the selected row as the last child of its previous row, whereas the outdent action moves the selected row as a sibling to its parent row.
To use the indent and outdent feature, inject the RowDD
module in the Tree Grid. The tree grid toolbar has the built-in items to execute indent and outdent actions. Define this by using the toolbar property.
<template>
<div id="app">
<ejs-treegrid :dataSource='data' childMapping='subtasks' :treeColumnIndex='1' :selectedRowIndex='2' height='270px' :toolbar='toolbar'>
<e-columns>
<e-column field='taskID' :isPrimaryKey='true' headerText='Task ID' width=90 textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width=180 ></e-column>
<e-column field='priority' headerText='Priority' width=80 textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width=80 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { TreeGridComponent as EjsTreegrid, Toolbar, RowDD,
ColumnDirective as EColumn, ColumnsDirective as EColumns
} from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from "./datasource.js";
const data = sampleData;
const toolbar = ['Indent', 'Outdent'];
provide('treegrid', [ Toolbar, RowDD ]);
</script>
<template>
<div id="app">
<ejs-treegrid :dataSource='data' childMapping='subtasks' :treeColumnIndex='1' :selectedRowIndex='2' height='270px' :toolbar='toolbar'>
<e-columns>
<e-column field='taskID' :isPrimaryKey='true' headerText='Task ID' width=90 textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width=180 ></e-column>
<e-column field='priority' headerText='Priority' width=80 textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width=80 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import { TreeGridComponent, Toolbar, RowDD, ColumnDirective, ColumnsDirective } from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-treegrid":TreeGridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
},
data() {
return {
data: sampleData,
toolbar: ['Indent', 'Outdent']
};
},
provide: {
treegrid: [ Toolbar, RowDD ]
}
}
</script>
Indent/Outdent a row programmatically
You can change the hierarchy level of record programmatically using indent
and outdent
methods.
<template>
<div id="app">
<button v-on:click="Indenting()">Indent</button>
<button v-on:click="Outdenting()">Outdent</button>
<ejs-treegrid :dataSource='data' ref="treegrid" childMapping='subtasks' :treeColumnIndex='1' height='270px'>
<e-columns>
<e-column field='taskID' :isPrimaryKey='true' headerText='Task ID' width=90 textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width=180 ></e-column>
<e-column field='priority' headerText='Priority' width=80 textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width=80 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script setup>
import { provide, ref } from "vue";
import { TreeGridComponent as EjsTreegrid, RowDD, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from "./datasource.js";
const data = sampleData;
const treegrid = ref(null);
const Indenting = function() {
treegrid.value.ej2Instances.grid.indent(treegrid.value.ej2Instances.grid.getCurrentViewRecords()[2]);
};
const Outdenting = function() {
treegrid.value.ej2Instances.grid.outdent(treegrid.value.ej2Instances.grid.getCurrentViewRecords()[2]);
};
provide('treegrid', [ RowDD ]);
</script>
<template>
<div id="app">
<button v-on:click="Indenting()">Indent</button>
<button v-on:click="Outdenting()">Outdent</button>
<ejs-treegrid :dataSource='data' ref="treegrid" childMapping='subtasks' :treeColumnIndex='1' height='270px'>
<e-columns>
<e-column field='taskID' :isPrimaryKey='true' headerText='Task ID' width=90 textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width=180 ></e-column>
<e-column field='priority' headerText='Priority' width=80 textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width=80 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import { TreeGridComponent, RowDD, ColumnDirective, ColumnsDirective } from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-treegrid":TreeGridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
},
data() {
return {
data: sampleData
};
},
methods: {
Indenting() {
this.$refs.treegrid.indent(this.$refs.treegrid.getCurrentViewRecords()[2]);
},
Outdenting() {
this.$refs.treegrid.outdent(this.$refs.treegrid.getCurrentViewRecords()[2]);
}
},
provide: {
treegrid: [ RowDD ]
}
}
</script>