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

orgchart and Root parent id

8 Answers 48 Views
This is a migrated thread and some comments may be shown as answers.
Olivier
Top achievements
Rank 2
Olivier asked on 16 Jun 2014, 01:58 PM
Hello

When i use in the OrgChart , the business object to databinding ,it's work very well.

But if my Root guy on the OrgChart do not Containd parent_id == 0, the orgchart doesn't work ! and doesn't appear.

My customer use the multi level marketing (mlm) , and if the user root get a tree , it's possible his parent_id don't get a Zero in his value.

It's possible to correct in the OrgChart

id    parent_id
5       4
6       5
7       5
8       5

it' should be work.

thanks 

8 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 19 Jun 2014, 01:33 PM
Hi Oliver,

Such structure is invalid. The OrgChart expects to have at least one root item, where the parent_id is null.

For example:
id    parent_id
5       4
6       5
7       5
8       5
4       null

However if the data returned by your database is similar, try to put this data in some collection of objects, then replace all 0 with NULL values. Finally bound  the OrgChart to the collection with the valid data.

DB <-> Collection <-> OrgChart

Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Olivier
Top achievements
Rank 2
answered on 28 Aug 2014, 02:24 PM
Hello

Can you accept  Zero : "0" or null value in ROOT item : please ?

I don't usually  use Null value in my database.

thanks
Olivier
0
Shinu
Top achievements
Rank 1
answered on 29 Aug 2014, 06:17 AM
Hi Olivier,

As far as I know this is not possible because DataFieldParentID must be null if it is of nullable (e.g. int?) or reference (e.g. string) type.

Thanks,
Shinu.
0
Olivier
Top achievements
Rank 2
answered on 29 Aug 2014, 08:11 AM
Hello there

everything is possible, in programming, if you will not start at the root node,
Why Would not this option?
I had to make a view to work around this big problem.

it's not difficult to  accept any value, to start the root what we want.

Do you understand me ?
0
Hristo Valyavicharski
Telerik team
answered on 02 Sep 2014, 10:22 AM
Hi,

The DataFieldParentID cannot be null when the OrgChart is populated from a database. For example if you have the following table structure:

int ID (Primary Key)
nvarchar Text
int ParentID (Foreign Key)

the dababase will not allow you to enter new record, where the ParentID is 0 and if there are not record with ID=0.

However it is possible to populate the OrgChart with the following code:

<telerik:RadOrgChart runat="server" ID="orgChart"></telerik:RadOrgChart>

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        List<Item> items = new List<Item>();
        for (int i = 0; i < 3; i++)
        {
            items.Add(new Item()
                {
                    Id = i,
                    Name = "Parent " + i.ToString(),
                    ParentID = 0
                });
        }
 
        for (int i = 0; i < 3; i++)
        {
            items.Add(new Item()
                {
                    Id = i,
                    Name = "Child " + i.ToString(),
                    ParentID = 1
                });
        }
 
        orgChart.DataSource = items;
        orgChart.DataTextField = "Name";
        orgChart.DataFieldID = "Id";
        orgChart.DataFieldParentID = "ParentID";
 
        orgChart.DataBind();
    }
}
 
public class Item
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int ParentID { get; set; }
}


Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Olivier
Top achievements
Rank 2
answered on 02 Sep 2014, 12:14 PM
on day , you ll upgrade with my tips.

In orgChart, the null value for the parent id , is the BIG BOSS == CEO

If we want to start with Chief Employee only , it's not possible without your difficulty code not plug and play !
0
Hristo Valyavicharski
Telerik team
answered on 03 Sep 2014, 11:03 AM
Hi Oliver,

I'm not sure if I understood correctly what the problem is. The OrgChart can display all kind of hierarchical structures.  So if your data base is something similar to this http://screencast.com/t/J7TL8Gb8GbT
then you should get the desired behavior. http://screencast.com/t/NtuJZlroAo

To start with the "Chief Employee" only you can modify the select command of  your data source.

Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
imane
Top achievements
Rank 1
answered on 03 Jan 2018, 11:00 AM

Hi Friend,

I want to use orgchart in asp mvc with database i find code in internet with this methode

public ActionResult _OrgChart(){return Json(DiagramDataRepository.OrgChart(), JsonRequestBehavior.AllowGet);}

but i don't know how to use this and how to create this methode DiagramDataRepository.OrgChart()

please help mee

 

Asked by
Olivier
Top achievements
Rank 2
Answers by
Hristo Valyavicharski
Telerik team
Olivier
Top achievements
Rank 2
Shinu
Top achievements
Rank 1
imane
Top achievements
Rank 1
Share this question
or