I build the tree like this:
@(Html.Infragistics().Tree("Tree1", Model1.Tree1);
When I try to open a igTree inside a jQuery dialog doing this:
$('#select-states-button').click(function() { var $dialog = $('#States').dialog({autoOpen: false,resizable: false, width: 1000,height: 800,maxHeight: 800, modal: true,buttons: { "Ok": function() { $(this).dialog("close"); } },title: 'Select States'});
$dialog.dialog('open');// prevent the default action, e.g., following a linkreturn false; });
I get this error in the file ig.ui.js:
case
'loadOnDemand':
throw new Error($.ig.Tree.locale.setOptionError + option);
I found a work around by not using the MVC helper function but instantiating the control in jquery.
$('#Tree1').igTree({ dataSource: [{"Name":"Alabama","StateId":1,"City":{}}, ... all the other courts are here... ], loadOnDemand: true, dataSourceUrl: '/Home/TreeGetData', checkboxMode: 'tristate', singleBranchExpand: true, parentNodeImageUrl: 'Computer.png', leafNodeImageUrl: 'Computer.png', bindings: { textKey: 'Name', primaryKey: 'StateId', valueKey: 'StateId', childDataProperty: 'Courts', bindings: { textKey: 'Name', primaryKey: 'CityId', valueKey: 'CityId' } } });
My question is how do I instantiate the control in jquery and use the parent data (Model.Tree1)?
Hi there,
Is it possible for you to attach a small isolated sample that reproduces the issue and I would be happy to take a look at it and to help you further!
Thank you for using the Infragistics forums!
I've created a new project that just shows the error. Now it works without an error but you can't click on the tree. The project connects to a database. Do you want me to zip the project anyways? Where do I send it?
Hello there,
I was just wondering whether you got your issue resolved?
Could you please try returning View("Index", model.Tree1) from your controller?
Thanks!
I found out the issue only happens when I use theTreeModel.
Here is how it is setup when it doesn't work -
Here is my Model:
public class TreeModels { public TreeModel Tree1 { get; set; } }
Here is my Controller:
var db = new MotherShipEntities(); var col1 = db.States.Where("it.Name LIKE '[A-K]%'");
TreeBindings tbStates = new TreeBindings(); tbStates.TextKey = "Name"; tbStates.PrimaryKey = "StateId"; tbStates.ValueKey = "StateId"; tbStates.ChildDataProperty = "Cities"; TreeBindings tbCities = new TreeBindings(); tbCities.TextKey = "Name"; tbCities.PrimaryKey = "CityId"; tbCities.ValueKey = "CityId"; tbStates.Bindings = tbCities; // ======================== TreeModel treeModel1 = new TreeModel(); treeModel1.ID = "TreeInController1"; // Configure data source treeModel1.DataSource = col1; // Configure specific display and interraction properties treeModel1.LoadOnDemand = true; treeModel1.DataSourceUrl = Url.Action("TreeGetData"); treeModel1.CheckboxMode = CheckboxMode.TriState; treeModel1.SingleBranchExpand = true; treeModel1.ParentNodeImageUrl = "Computer.png"; treeModel1.LeafNodeImageUrl = "Computer.png"; // Define bindings treeModel1.Bindings = new TreeBindings(); treeModel1.Bindings.TextKey = "Name"; treeModel1.Bindings.PrimaryKey = "StateId"; treeModel1.Bindings.ValueKey = "StateId"; //treeModel1.Bindings.ImageUrlKey = "ImageUrl"; treeModel1.Bindings.ChildDataProperty = "Cities"; treeModel1.Bindings = tbStates; // ========================
var model = new TreeModels() { Tree1 = treeModel1, }; return View("Index", model);'
and here is my cshtml:
@(Html.Infragistics().Tree(this.Model.Tree1 as TreeModel))
To make it work this is my controller:
return View(col1);
and this is my cshtml:
@(Html. Infragistics(). Tree(). Bindings( bindings => { bindings. TextKey("Name"). PrimaryKey("StateId"). ValueKey("StateId"). ChildDataProperty("Cities"). Bindings(b1 => { b1. TextKey("Name") .ValueKey("CityId") .PrimaryKey("CityId"); }); }). DataSourceUrl(Url.Action("TreeGetData")). LoadOnDemand(true). DataSource(Model). DataBind(). Render() )
When I do it that way (using the MVC helper) it works. I can click on the tree and it will expand or check.
Here is how I call the dialog in both examples:
$('#select-states-button').click(function() { $('#test-dialog').dialog(); });
Here is my load on demand callback: used in both examples
public JsonResult TreeGetData(string path, string binding, int depth) { var ctx = new MotherShipEntities(); TreeModel model = new TreeModel(); switch (depth) { case 0: model.DataSource = ctx.States; break; case 1: model.DataSource = ctx.Cities; break; default: model.DataSource = ctx.States; break; } return model.GetData(path, binding); }
Hey Jadem,
Just attach your zip to your post.