This is a migrated thread and some comments may be shown as answers.

Adding a searchbox functionality

1 Answer 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Emil
Top achievements
Rank 1
Emil asked on 06 Apr 2017, 02:43 PM

Ive been working off this demo

http://demos.telerik.com/aspnet-mvc/treeview/remote-data-binding

 

And I can populate my treeview without any problems

Ive been trying to get the value of a textbox 

 

<input type="text" class="form-control" id="searchString" placeholder="Leit" value="" size="50" onkeypress="if (event.which == 13) { $('treeview').getTreeView().dataSource.read(); }">

as you can see the textbox is called searchString

this is my treeview in my cshtml file

@(Html.Kendo().TreeView()
        .Name("treeview")
        .TemplateId("treeview-template")
        .DataSource(source =>
        {
        source.Read(read => read.Action("Read_TemplateData", "Home", new { searchString = "" })) ;
        })
    )

I dont quite know how to get the contents of that textbox into the searchString = since I usually do this by doing + $('searchString').val() which just concatenates the value on the end of the url.

the read_templateData is also the "standard" action.

I would like to be able to enter a searchtext in the searchbox and only return lines where the .text field contains what is in the searchString textbox. So I would use the .contains(searchString) of a list server side.

 

any ideas ?

Regards,

Emil

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 07 Apr 2017, 02:45 PM
Hello Emil,

You can send an additional parameter to the action through the TreeView data source read data option. The following works at my end successfully sending the text entered in the textbox to the action. Note that the property of the object returned by the data function and the Action parameter have the same name (searchString):

Calling the TreeView's dataSource read method:
<input type="text" class="form-control" id="searchString" placeholder="Leit" value="" size="50" onkeypress="if (event.which == 13) {
    $('#treeview').data('kendoTreeView').dataSource.read(); }">

Data method:
.Action("Read_TemplateData", "Home").Data("addParameters")

Function:
function addParameters() {
    return {
        searchString: $('#searchString').val()
    };
}

Action:
public JsonResult Read_TemplateData(int? id, string searchString)



Regards,
Ivan Danchev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
Emil
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or