Local data in Vue Treegrid component
16 Mar 20237 minutes to read
In Local Data binding, data source for rendering the TreeGrid control is retrieved from the same application locally.
Two types of Data binding are possible with the TreeGrid control.
- Hierarchical Datasource binding
- Self-Referential Data binding (Flat Data)
To bind local data to the treegrid, you can assign a JavaScript object array to the dataSource
property. The local data source can also be provided as an instance of the DataManager
.
By default,
DataManager
usesJsonAdaptor
for local data-binding.
Hierarchy data source binding
The childMapping
property is used to map the child records in hierarchy data source.
The following code example shows you how to bind the hierarchical local data into the TreeGrid control.
<template>
<div id="app">
<ejs-treegrid :dataSource="data" childMapping='subtasks' :treeColumnIndex='1' :allowPaging='true' :pageSettings='pageSettings'>
<e-columns>
<e-column field='taskID' headerText='Task ID' width=70 textAlign='Right'></e-column>
<e-column field='taskName' headerText='Task Name' width=200></e-column>
<e-column field='startDate' headerText='Start Date' width=90 format="yMd" textAlign='Right'></e-column>
<e-column field='duration' headerText='Duration' width=80 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import Vue from "vue";
import { TreeGridPlugin, Page } from "@syncfusion/ej2-vue-treegrid";
import { sampleData } from './datasource.js';
Vue.use(TreeGridPlugin);
export default {
data () {
return {
data: sampleData,
pageSettings: { pageSize: 7 }
};
},
provide: {
treegrid: [ Page ]
}
}
</script>
> * Remote data binding is not supported for Hierarchy Data.
Self-Referential data binding (Flat data)
TreeGrid is rendered from Self-Referential data structures by providing two fields, ID field and parent ID field.
-
ID Field: This field contains unique values used to identify nodes. Its name is assigned to the
idMapping
property. -
Parent ID Field: This field contains values that indicate parent nodes. Its name is assigned to the
parentIdMapping
property.
<template>
<div id="app">
<ejs-treegrid :dataSource="data" idMapping='TaskID' parentIdMapping='parentID' :treeColumnIndex='1' :allowPaging='true' :pageSettings='pageSettings'>
<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=90 format="yMd" textAlign='Right'></e-column>
<e-column field='Duration' headerText='Duration' width=80 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import Vue from "vue";
import { TreeGridPlugin, Page } from "@syncfusion/ej2-vue-treegrid";
import { projectData } from './datasource.js';
Vue.use(TreeGridPlugin);
export default {
data () {
return {
data: projectData,
pageSettings: { pageSize: 7 }
};
},
provide: {
treegrid: [ Page ]
},
}
</script>
Herewith we have provided list of reserved properties and the purpose used in TreeGrid. We recommend to avoid these reserved properties for Internal purpose(To get rid of conflicts).
Reserved keywords | Purpose |
---|---|
childRecords | Specifies the childRecords of a parentData |
hasChildRecords | Specifies whether the record contains child records |
hasFilteredChildRecords | Specifies whether the record contains filtered child records |
expanded | Specifies whether the child records are expanded |
parentItem | Specifies the parentItem of childRecords |
index | Specifies the index of current record |
level | Specifies the hierarchy level of record |
filterLevel | Specifies the hierarchy level of filtered record |
parentIdMapping | Specifies the parentID |
uniqueID | Specifies the unique ID of a record |
parentUniqueID | Specifies the parent Unique ID of a record |
checkboxState | Specifies the checkbox state of a record |
isSummaryRow | Specifies the summary of a record |
taskData | Specifies the main data |
primaryParent | Specifies the Primary data |