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

TreeList with Id and parentId string type

6 Answers 325 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Kajal
Top achievements
Rank 1
Kajal asked on 13 Nov 2015, 08:41 PM

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);

        }

6 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 17 Nov 2015, 05:04 PM

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
0
John
Top achievements
Rank 1
answered on 26 Aug 2016, 03:00 PM

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

 

0
Boyan Dimitrov
Telerik team
answered on 30 Aug 2016, 11:24 AM

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
0
Justin
Top achievements
Rank 1
answered on 28 Sep 2018, 10:32 PM

I have found that the original post was correct. Converting a  to string and then passing those values, while setting the root nodes to null fails and says there are no records.

However, if you use an empty string, instead of null, it works fine.

This may apply to all cases where you are using a string value.

 

 

0
Boyan Dimitrov
Telerik team
answered on 02 Oct 2018, 03:38 PM
Hi,

Thank you for sharing this information with the community. I believe that it will help someone having similar scenario. 

Regards,
Boyan Dimitrov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
terrysmith
Top achievements
Rank 1
answered on 04 Oct 2019, 09:20 PM
null -> Guid.Empty. Exactly what I needed. Thank you!
Tags
TreeList
Asked by
Kajal
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
John
Top achievements
Rank 1
Justin
Top achievements
Rank 1
terrysmith
Top achievements
Rank 1
Share this question
or