TreeList with Id and parentId string type

4 posts, 0 answers
  1. Kajal
    Kajal avatar
    3 posts
    Member since:
    Feb 2014

    Posted 13 Nov 2015 Link to this post

    Hi,

    I have a requirement to bind data to TreeList where Id and ParentId field are of type string but this does not seem to work. Is it possible? 

    I have tried making id and parentId field int and then its works.

    TreeList:

    <div class="demo-section k-header">
        @(Html.Kendo().TreeList<JobErrorLogController.MyClass>()
              .Name("myClassTreelist")
              .Columns(columns =>
              {
                  columns.Add().Field(e => e.Item).Width(220);
              })
              .Filterable()
              .Sortable()
              .DataSource(dataSource => dataSource
                  .Read(read => read.Action("AllData", "JobErrorLog"))
                  .ServerOperation(false)
                  .Model(m =>
                  {
                      m.Id(f => f.id);
                      m.ParentId(f => f.parentId);
                      //m.Expanded(true);
                      m.Field(f => f.Item);
                  })
              )
              .Height(540)
              )
    </div>

     Class that is bind to TreeList:

    public class MyClass
     {
     public static IList<MyClass> TestData = new List<MyClass>()
     {
     new MyClass() {id = "parent1", Item = "Item0", parentId = null},
     new MyClass() {id = "child1", Item = "Item1", parentId = "parent1"}
     };
     public string id { get; set; }
     public string parentId { get; set; }
     public string Item { get; set; }
     }

    Controller's code:  

    public JsonResult AllData([DataSourceRequest] DataSourceRequest request)
     
            {
     
                var result = MyClass.TestData.ToTreeDataSourceResult(request,
     
                    e => e.id,
     
                    e => e.parentId
     
                ); 
                return Json(result, JsonRequestBehavior.AllowGet);

            }

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 17 Nov 2015 Link to this post

    Hello Kajal,

     

    I prepared a sample example that shows how the TreeList should work fine with string type for the Id and the parent id properties. Please refer to the http://dojo.telerik.com/UPosU example. 

     

    Regards,
    Boyan Dimitrov
    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. John
    John avatar
    12 posts
    Member since:
    Jul 2016

    Posted 26 Aug in reply to Boyan Dimitrov Link to this post

    Hi Boyan,

    I'm in a similar situation as OP, using MVC Razor code and your solution is in javascript showing how to set the id and parentId to type string.  How one set that up in MVC.

    Thanks,

    John

     

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 30 Aug Link to this post

    Hello John,

    In the MVC the type of the field is retrieved from the Model definition. If the Model id is defined as string should be treated as string. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready