Using the following example, expand the first (unique) node and you will receive two alerts:
Validating Expansion and
Not Allowed. After you close both alerts, try to expand the node again and you'll note that the node is
died but it is expected that the node expands successfuly.
1 - View
<!DOCTYPE html>
<html>
<head runat="server">
<title>Index</title>
<script type="text/javascript">
var isFirstExpand = true;
var beforeExpand = function (item, options) {
alert('Validating Expansion');
if (isFirstExpand) {
alert('Not Allowed');
isFirstExpand = false;
return false;
}
return false;
}
</script>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:TreePanel ID="TreePanel2" SelType="Checkbox" runat="server" Title="Tree" Height="700"
Width="400" Margins="10" RootVisible="false" Border="false">
<Listeners>
<BeforeItemExpand Fn="beforeExpand" />
</Listeners>
<Store>
<ext:TreeStore ID="TreeStore1" runat="server">
<Proxy>
<ext:AjaxProxy Url="/Example/loadNodeChildren">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="data" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Task" />
</Fields>
</ext:Model>
</Model>
</ext:TreeStore>
</Store>
<Root>
<ext:Node NodeID="0" Text="Root" />
</Root>
<ColumnModel>
<Columns>
<ext:TreeColumn ID="TreeColumn1" runat="server" Text="Task" Flex="2" Sortable="true"
DataIndex="Task" />
</Columns>
</ColumnModel>
</ext:TreePanel>
</body>
</html>
2 - Action
public StoreResult loadNodeChildren()
{
StoreResult result = new StoreResult();
NodeCollection nodes = new NodeCollection(false);
Node no = new Node();
no.NodeID = DateTime.Now.Second.ToString();
no.CustomAttributes.Add(new ConfigItem { Name = "Task", Value = no.NodeID, Mode = ParameterMode.Value });
nodes.Add(no);
result.Data = nodes.ToJson();
return result;
}