Is it possible to set the DataSource of a Kendo ListView without having the DataSource then call the read() method?
I have a main DataSource that I am using on a ListView and all of the child ListViews but am just filtering it for each ListView depending on a few conditions. The way that I'm doing this is once all of the data has been bound to the main ListView then I create all of the child ListViews and assign the same datasource with filtering.
The issue I'm having here is once I assign the filtered DataSource to the new ListView it seems to be calling the read method again.
baSurveyGroupTemplateDataSource: new kendo.data.DataSource({
transport: {
read: {
async: false,
url: "/Url/to/data"
dataType: "json",
type: "GET",
data: {
id: $("#TemplateId").val()
},
}
}
}),
groupDataBound: function (e) {
$(".childBaSuveyGroupTemplate").each(function () {
viewModel.seedGroup(this);
});
},
seedGroup: function (parentGroup) {
var childrenGroupList = $(parentGroup);
var parentGroupId = childrenGroupList.data("id");
var childrenGroupDataSource = new kendo.data.DataSource(viewModel.baSurveyGroupTemplateDataSource);
childrenGroupDataSource.query({
filter: ({ field: "BaSurveyGroupTemplateParentId", operator: "eq", value: parentGroupId })
});
childrenGroupList.kendoListView({
template: kendo.template($("#baSurveyGroupTemplateDisplayTemplate").html()),
dataSource: childrenGroupDataSource
});
}
Let me know if I need to clarify anything. It's hard to try and put what I'm doing and the problem I'm having into words.
Try adding this to your ListView configuration:
autoBind: false
From the kendo documentation at http://docs.telerik.com/kendo-ui/api/javascript/ui/listview#configuration-autoBind
If set to false the widget will not bind to the data source during initialization. In this case data binding will occur when the change event of the data source is fired. By default the widget will bind to the data source specified in the configuration.
Setting autoBind to false is useful when multiple widgets are bound to the same data source. Disabling automatic binding ensures that the shared data source does not make more than one request to the remote service.
Then manually trigger the datasource read once you have everything set:
childrenGroupDataSource.read(); // "read()" will fire the "change" event of the dataSource and the widget will be bound