Hello,
I have one function that return hierarchical dataset.
This dataset is set as datasource for Autocomplete control, which uses just parent portion of data.
Goal: do not make another request to server for data, after selection of item in Autocomplete _copy_ selected dataitem (with children) from autocomplete dataset to treeview - i.e make it treview's dataset. It is Ok also to copy into treeview not just selected item but entire set returned for Autocomplete after search.
So far no luck...
Code:
@(Html.Kendo().AutoComplete()
.Name("findvendor")
.DataTextField("company_name")
.Filter("contains")
.Placeholder("Find Vendor...")
.MinLength(3)
.DataSource(source => {
source.Read(read =>{read.Action("search_vendors", "content")
.Data("function () {return {text: $('#findvendor').val() };}");}
)
.ServerFiltering(true);})
.Events(e=> e.Select("content_addvendor_vendor_found"))
.Deferred()
)
Treeview (which suppose to be filled with Autocomplete selected item Parent and its children):
@(Html.Kendo().TreeView().Deferred()
.Events(ev => ev.Select("content_addvendor_chosen"))
.HtmlAttributes(new { @style = "color:black;overflow: hidden;"})
.Name("contactstree")
.BindTo(new List<ca.Models.pcm_vendor>(),(Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
{
mappings.For<ca.Models.pcm_vendor>(bound => bound.ItemDataBound((node, vendor) =>
{
node.Text = vendor.abbreviation + ':' + vendor.company_name;
node.Id = vendor.abbreviation;
node.SpriteCssClasses = "cus-sort-quantity";
})
.Children(e => e.contacts));
mappings.For<ca.Models.pcm_vendor_contact>(binding => binding.ItemDataBound((item, contact) =>
{
item.Text = contact.name;
item.Id = '+'+contact.initials;
item.SpriteCssClasses = "cus-page-white-tux";
}));
})
)
(since I use deferred load, this script placed at the top of the page)
<script>
function content_addvendor_vendor_found(e)
{
var new_ds = new kendo.data.HierarchicalDataSource({ data:$("#findvendor").data("kendoAutoComplete").dataSource.data())});
new_ds.read();
$("#contactstree").data("kendoTreeView").setDataSource(new_ds);
//$("#contactstree").kendoTreeView({ dataSource: new_ds }).data("kendoTreeView");
}
function content_addvendor_chosen(e) {
alert('Node selected');
}
</script>
Thank you!!!
I have one function that return hierarchical dataset.
This dataset is set as datasource for Autocomplete control, which uses just parent portion of data.
Goal: do not make another request to server for data, after selection of item in Autocomplete _copy_ selected dataitem (with children) from autocomplete dataset to treeview - i.e make it treview's dataset. It is Ok also to copy into treeview not just selected item but entire set returned for Autocomplete after search.
So far no luck...
Code:
@(Html.Kendo().AutoComplete()
.Name("findvendor")
.DataTextField("company_name")
.Filter("contains")
.Placeholder("Find Vendor...")
.MinLength(3)
.DataSource(source => {
source.Read(read =>{read.Action("search_vendors", "content")
.Data("function () {return {text: $('#findvendor').val() };}");}
)
.ServerFiltering(true);})
.Events(e=> e.Select("content_addvendor_vendor_found"))
.Deferred()
)
Treeview (which suppose to be filled with Autocomplete selected item Parent and its children):
@(Html.Kendo().TreeView().Deferred()
.Events(ev => ev.Select("content_addvendor_chosen"))
.HtmlAttributes(new { @style = "color:black;overflow: hidden;"})
.Name("contactstree")
.BindTo(new List<ca.Models.pcm_vendor>(),(Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
{
mappings.For<ca.Models.pcm_vendor>(bound => bound.ItemDataBound((node, vendor) =>
{
node.Text = vendor.abbreviation + ':' + vendor.company_name;
node.Id = vendor.abbreviation;
node.SpriteCssClasses = "cus-sort-quantity";
})
.Children(e => e.contacts));
mappings.For<ca.Models.pcm_vendor_contact>(binding => binding.ItemDataBound((item, contact) =>
{
item.Text = contact.name;
item.Id = '+'+contact.initials;
item.SpriteCssClasses = "cus-page-white-tux";
}));
})
)
(since I use deferred load, this script placed at the top of the page)
<script>
function content_addvendor_vendor_found(e)
{
var new_ds = new kendo.data.HierarchicalDataSource({ data:$("#findvendor").data("kendoAutoComplete").dataSource.data())});
new_ds.read();
$("#contactstree").data("kendoTreeView").setDataSource(new_ds);
//$("#contactstree").kendoTreeView({ dataSource: new_ds }).data("kendoTreeView");
}
function content_addvendor_chosen(e) {
alert('Node selected');
}
</script>
Thank you!!!