PDA

View Full Version : [CLOSED] How to rebind TreePanel RootNode from script



PriceRightHTML5team
Dec 11, 2013, 7:37 AM
Hi,

I have tree panel with me, using same tree panel I want show next data (same tree panel with different data) in tree panel. So I was trying to fetch data by direct request and change root node of tree panel.

Can you please tell me how to bind root node of tree panel from the script?

Let me know if I am doing something wrong or any different approach is there.

// Code

//Controller


public class SubmitController : Controller
{
public ActionResult Index()
{
return View(GetTreeNodeList());
}

public ActionResult SubmitNodes()
{
return this.Direct(GetTreeNodeList1());
}
private List<Ext.Net.Node> GetTreeNodeList1()
{

Node root1 = new Node();
root1.Text = "ds";

bool submit = true;

for (int i = 0; i < 10; i++)
{
Node node = new Node();
node.NodeID = (i + 1).ToString();
node.Text = "edoN" + (i + 1);
node.Leaf = false;
node.Expandable = true;
node.Checked = true;
node.CustomAttributes.Add(new ConfigItem("submit", JSON.Serialize(submit), ParameterMode.Raw));
for (int j = 0; j < 3; j++)
{
Node childNode = new Node();
childNode.NodeID = (j + 1).ToString();
childNode.Text = "edoN" + (j + 1);
childNode.Leaf = true;
childNode.Checked = true;
childNode.CustomAttributes.Add(new ConfigItem("submit", JSON.Serialize(submit), ParameterMode.Raw));
node.Children.Add(childNode);
submit = !submit;
}
root1.Children.Add(node);
}


List<Ext.Net.Node> lstNode = new List<Node>();
lstNode.Add(root1);
return lstNode;
}
private List<Ext.Net.Node> GetTreeNodeList()
{

Node root1 = new Node();

root1.Text = "ds";

bool submit = true;

for (int i = 0; i < 10; i++)
{
Node node = new Node();
node.NodeID = (i + 1).ToString();
node.Text = "Node" + (i + 1);
node.Leaf = false;
node.Expandable = true;
node.Checked = true;
node.CustomAttributes.Add(new ConfigItem("submit", JSON.Serialize(submit), ParameterMode.Raw));
for (int j = 0; j < 3; j++)
{
Node childNode = new Node();
childNode.NodeID = (j + 1).ToString();
childNode.Text = "Node" + (j + 1);
childNode.Leaf = true;
childNode.Checked = true;
childNode.CustomAttributes.Add(new ConfigItem("submit", JSON.Serialize(submit), ParameterMode.Raw));
node.Children.Add(childNode);
submit = !submit;
}
root1.Children.Add(node);
}

List<Ext.Net.Node> lstNode = new List<Node>();
lstNode.Add(root1);
return lstNode;
}
}


//View



@model List<Ext.Net.Node>
@{
ViewBag.Title = "TreePanel Submit - Ext.NET MVC Examples";
Layout = "~/Views/Shared/_BaseLayout.cshtml";
}
@section headtag
{
<script type="text/javascript">
function mytree(result)
{
var rs = result;
App.ds.setRootNode(rs.result[0]);
App.ds.reload();
}
</script>
}
}
@section example
{
<h1>TreePanel Submit</h1>
@(
Html.X().FormPanel().ID("frmTreepanel")
.Items(
Html.X().TreePanel().ID("ds")
.Icon(Icon.Anchor)
.Title("Tree")
.Width(550)
.RootVisible(false)
.Root(Model[0])

.Fields(
Html.X().ModelField().Name("submit").Type(ModelFieldType.Boolean)
)
)
.Buttons(
Html.X().Button().DirectEvents(de=>{
de.Click.Url = Url.Action("SubmitNodes");
de.Click.Success = "mytree(result);";
})
)
)
}

Daniil
Dec 11, 2013, 9:04 AM
Hi @PriceRightHTML5team,

Please take a look at:
http://mvc.ext.net/#/TreePanel_Basic/Refresh_Static_Tree/