I'm trying to manually add an item to my grid's datasource, and can't seem to get it to work, but I may just be missing something fundamental with Vue components.
My grid is located in a child Vue component template, where the datasource is given to it by the parent (it's an array of objects). When it binds, it does display my two sample rows from the array, but can't get a new row to be added dynamically.
Grid:
<kendo-grid v-once ref="diagnosisCodes" :data-source="dataSource.DiagnosisCodes" :selectable="true" :scrollable="false">
<kendo-grid-column field="SequenceNumber" title="@Localizer["Sequence"]" :width="100"></kendo-grid-column>
<kendo-grid-column field="DiagnosisCode" title="@Localizer["Diagnosis Code"]" :width="140"></kendo-grid-column>
<kendo-grid-column field="Description" title="@Localizer["Description"]"></kendo-grid-column>
<kendo-grid-column :command="['destroy']" title=" " :width="120"></kendo-grid-column>
</kendo-grid>
In a method of my child component, I'm basically trying to do this, just to see if I can get a new row to appear in the grid:
const dc = <Vue>this.$refs.diagnosisCodes;
const item: any = { SequenceNumber: 3, DiagnosisCode: "M225.7", Description: "Fingers crossed" };
dc.$props.dataSource.push(item);
The console error is attached, but the error is "[Vue warn]: Error in callback for watcher "dataSource": "TypeError: dataSource.fetch is not a function". I'm new to using Kendo Vue, so if I'm doing this wrong, how can I dynamically add to my Vue grid datasource, in order to get new rows to appear?
So if I rework my template, so the grid is bound to an actual kendo-datasource, instead of a primitive array, then it works. The "push" was adding to the datasource before (saw that in the F12 tools), but the grid seems to think it is bound to a kendoDatasource, as the error said it was trying to call "fetch", which doesn't exist on my array. Maybe the grid was supposed to automatically wrap up my array into a kendodatasource, but it didn't, or some binding code needs to change, but it feels like it might be a bug to me.
Working version of template:
<kendo-datasource ref="diagnosisCodesDataSource"
:data="dataSource.DiagnosisCodes"
:server-filtering="false">
</kendo-datasource>
<kendo-grid v-once ref="diagnosisCodes" :data-source-ref="'diagnosisCodesDataSource'" :selectable="true" :scrollable="false">
<kendo-grid-column field="SequenceNumber" title="@Localizer["Sequence"]" :width="100"></kendo-grid-column>
<kendo-grid-column field="DiagnosisCode" title="@Localizer["Diagnosis Code"]" :width="140"></kendo-grid-column>
<kendo-grid-column field="Description" title="@Localizer["Description"]"></kendo-grid-column>
<kendo-grid-column :command="['destroy']" title=" " :width="120"></kendo-grid-column>
</kendo-grid>
Working sample code:
const ds = <Vue>this.$refs.diagnosisCodesDataSource;
const item: any = { SequenceNumber: 3, DiagnosisCode: "M225.7", Description: "Fingers crossed" };
ds.$props.data.push(item);