I am trying to bind the data on Kendo UI with the data from Vuex getters.
I have tried the following but no luck. Please help whether where i am missing something on the vuex or on the kendo.
Kendo Extensions:
<kendo-grid :data-source="kendoDataSource">
</kendo-grid>
Components:
computed: {
customers() {
return this.$store.getters.customers;
}
},
data() {
return {
kendoDataSource: {
schema: {
data: function(response) {
return response;
},
model: {
id: "CustomerID",
fields: {
CompanyName: { type: "string" },
}
}
},
transport: {
read: function(options) {
options.success(this.customers);
}
}
}
};
I am getting the error. TypeError: Cannot read property 'length' of undefined
When i tried to debug the this.customers
in the transport of kendo the object this.customers
is always null.
The data are in the format as shown in below:
[
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste"
},
{
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados"
}
]
Store.js
export default {
state: {
customers: JSON.parse(JSON.stringify(customers))
},
getters: {
customers(state) {
return state.customers;
}
}
};
When i try to bind the data directly on options.success(this.customers);
Like the way shown below the grid get populated with the data successfully. But while i tried to bind using the getters
there is the error.
TypeError: Cannot read property 'length' of undefined
options.success([
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
},
{
"CustomerID": "ANATR",
"CompanyName": "Ana Trujillo Emparedados y helados",
}
]);
I think you want to use computed properties instead of data.