TreeList Textbox Filter

3 posts, 0 answers
  1. Brian
    Brian avatar
    4 posts
    Member since:
    Aug 2015

    Posted 18 Jan Link to this post

    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. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 20 Jan Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Brian
    Brian avatar
    4 posts
    Member since:
    Aug 2015

    Posted 21 Jan in reply to Nikolay Rusev Link to this post

    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

Back to Top