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

TreeList Textbox Filter

2 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 18 Jan 2016, 10:23 AM

Hello everybody,

I have a TreeList, which displays Data from an external DataSource. I asked my self, how I can access the filter by a textbox. I tried alot, but nothing of that worked. Is there any way to do this?

 This is what i got so far:

LogEntryView:

02.<div class="form-group">
03.        @(Html.Kendo().TextBox()
04.            .Name("tree-text-search")
05.        )
06.        @(Html.Kendo().Button()
07.            .Name("Search")
08.            .Content("Search")
09.            .Events(e => e.Click("onClick"))
10.        )
11.</div>
12.@(Html.Kendo().TreeList<HrLaborRelation.Web.Models.LogEntryViewModel>()
13.    .Name("Entries")
14.    .Columns(columns => {
15.        columns.Add().Field(f => f.EntityName);
16.        columns.Add().Field(f => f.SpecifiedType);
17.        columns.Add().Field(e => e.ColumnName);
18.        columns.Add().Field(e => e.NewValue);
19.        columns.Add().Field(e => e.OldValue);
20.        columns.Add().Field(e => e.Action);
21.        columns.Add().Field(e => e.CreatedBy);
22.        columns.Add().Field(e => e.EntryDate).Format("{0:dd/MM/yyyy HH:mm}");
23.    })
24.    .Resizable(true)
25.    .Reorderable(true)
26.    .ColumnMenu()
27.    .Filterable(true)
28.    .DataSource(dataSource => dataSource
29.        .Read(read => read.Action("GetEntries", "LogEntry"))
30.        .Model(m => {
31.            m.Id(f => f.LogEntryId);
32.            m.ParentId(f => f.ParentLogEntryId);
33.            m.Field(f => f.EntityName);
34.        })
35.    )
36.)
37.//I actually don't really know what this does
38.function onClick(e) {
39.        alert("Click");
40.        var treeview = $("#Entries").data("kendoTreeView"),
41.        searchContext = $("#tree-text-search").val()
42.        alert(searchContext)
43.        item = treeview.findByText(searchContext),
44.        dataItem = treeview.dataItem(item),
45.        nodeText = dataItem.EntityName;
46. 
47.        alert(nodeText);
48.        while (dataItem.parentNode()) {
49. 
50.            alert("Iterating");
51.            dataItem = dataItem.parentNode();
52.            dataItem.children.filter({ field: "EntityName", operator: "contains", value: nodeText });
53.            nodeText = dataItem.text;
54.        }
55.}

LogEntryController:

01.namespace HrLaborRelation.Web.Controllers
02.{
03.    public class LogEntryController: BaseController {
04. 
05.        // GET: LogEntry
06.        public ActionResult Index() {
07.            return View(db.LogEntries.Where(x => x.EntityId == -1).ToList());
08.        }
09.        public JsonResult GetEntries([DataSourceRequest]DataSourceRequest request, int? id, /*string searchText*/) {
10. 
11.            var entries = db.LogEntries.Include(e => e.ColumnLogEntries);
12.            if (id.HasValue) {
13.                entries = entries.Where(e => e.ParentLogEntryId == id);
14.            }
15.            //if(!string.IsNullOrEmpty(searchText)) {
16.            //    entries = entries.Where(e => e.EntityName.Contains(searchText));
17.            //}
18.            var result = entries.ToList().Select(e => new LogEntryViewModel(e, e.ColumnLogEntries.Any()));
19. 
20.            return Json(result.ToTreeDataSourceResult(request), JsonRequestBehavior.AllowGet);
21.        }
22.    }
23.}

Thanks for your help.

 Kind regards 

 Brian Haller

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 20 Jan 2016, 08:03 AM

Hello Brian,

 

In the click handler you are trying to get TreeView widget on element which has TreeList instead.

 

Also have in mind that the TreeList API is different than the TreeView.

 

Regards,
Nikolay Rusev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Brian
Top achievements
Rank 1
answered on 21 Jan 2016, 08:34 AM

Hello Nikolay,

ah well, that's right, didn't see it.

Now it works, after adjusting the Controller Method and changing the Name to TreeList.

Thank you very much!

Kind Regards

Brian Haller

Tags
General Discussions
Asked by
Brian
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Brian
Top achievements
Rank 1
Share this question
or