We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

treeview self reference database table

Thread ID:

Created:

Updated:

Platform:

Replies:

127621 Nov 28,2016 11:35 PM Nov 30,2016 07:05 AM JavaScript 1
loading
Tags: ejTreeView
issam
Asked On November 28, 2016 11:35 PM

Hi,

i have some troubles to get the treeview working with a self refererence table, something like this :
   public partial class CATEGORIE
    {
        public int ID_CATEGORIE { get; set; }
        public string CAT_TEXT { get; set; }
        public Nullable<int> CAT_ID_PARENT { get; set; }
        public Nullable<int> CAT_LEVEL { get; set; }
    }


here is my client side code :

     jQuery.ajax({
                url: "/Produits/GetFilters",
                success: function (data) {
                      $("#treeView").ejTreeView({
                        height : "300px",
                        fields: {
                            id: "ID", text: "CAT_TEXT",
                            hasChild: true, dataSource: data.cat, expanded: "expanded",
                            child: { dataSource: data.subcat, parentId: "CAT_ID_PARENT", text: "CAT_TEXT", id: "ID_CATEGORIE" }

                        },
                        showCheckbox: true
                    });
                },
                async: false
            });


the controller return multiple json objects for other filters :
    public JsonResult GetFilters()
        {


            var categories = (from n in ctx.CATEGORIES.Where(a => a.FA_LEVEL == 1).OrderBy(a => a.FA_DESIGNATION)
                            select new
                            {
                                ID_CATEGORIE = n.ID_CATEGORIE,
                                CAT_TEXT = n.CAT_TEXT,
                                CAT_ID_PARENT = n.CAT_ID_PARENT
                            }).ToList();

            var subcategories = (from n in ctx.CATEGORIES.Where(a => a.CAT_LEVEL != 1 && a.CAT_LEVEL != 1).OrderBy(a => a.CAT_TEXT)
                            select new
                            {
                               ID_CATEGORIE = n.ID_CATEGORIE,
                                CAT_TEXT = n.CAT_TEXT,
                                CAT_ID_PARENT = n.CAT_ID_PARENT
                            }).ToList();



/*  other stuff */ 

            return Json(new { cat= categories  subcat=subcategories, ........}, JsonRequestBehavior.AllowGet);

        }

the problem is that only the first level is displayed .
my goal is to have unlimited nested levels displayed for my self reference table .

any help is welcome, thanks .

Piramanayagam Ramakrishnan [Syncfusion]
Replied On November 30, 2016 07:05 AM

Hi Issam, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query. We would like to inform you that, the child mapper fields are applicable only for remote data source. For your requirement, you need to retrieve the entire data including all child nodes (all levels) from data source and map this data to dataSource property of TreeView control. Please refer the below code example, 
 
[Script] 
 
$.ajax({ 
    url: "/Home/GetFilters", 
    type: "POST", 
    dataType: "json", 
    success: function (data) { 
        $("#tree1").ejTreeView({ 
            height: "300px", 
            fields: { 
                id: "ID_CATEGORIE", text: "CAT_TEXT", parentId: "CAT_ID_PARENT", dataSource: data, hasChild: "hasChild", expanded: "expanded", 
            }, 
            showCheckbox: true 
        }); 
    }, 
}); 
 
[controller] 
 
public JsonResult GetFilters() 
{ 
    List<CATEGORIE> treeData = GetTreeData(); 
    var categories = (from n in treeData.OrderBy(a => a.CAT_TEXT) 
                        select new 
                        { 
                            ID_CATEGORIE = n.ID_CATEGORIE, 
                            CAT_TEXT = n.CAT_TEXT, 
                            CAT_ID_PARENT = n.CAT_ID_PARENT, 
                            hasChild = n.hasChild, 
                            expanded = n.expanded 
                        }).ToList(); 
    return Json(categories, JsonRequestBehavior.AllowGet); 
} 
 
 
For your reference, we have prepared a sample based on your requirement, and it can be downloaded from the following location: Sample 
 
Please let us know whether the provided sample is helpful in achieving your requirement. If not, get back to us with more information to proceed further.

Regards,
Piramanayagam R
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;