wilmercastrillon
Jun 24, 2021, 7:18 PM
I need reload a TreePanel, but the 'prepareToolbar' fails on reload, the 'record.data.type' are undefined, why?
@page
@model Project.Pages.ReloadTreePanelModel
@{
Layout = null;
}
<head>
<script type="text/javascript">
var gridCommand = [{
xtype: "button",
text: "button 1",
command: "commandbutton1",
}, {
xtype: "button",
text: "button 2",
command: "commandbutton2",
}];
var PrepareCommands = function (object, toolbar, rowIndex, record) {
if (record.data.depth == 0) {
toolbar.items.items[0].hide();
toolbar.items.items[1].hide();
}
if (record.data.type == '1') {
toolbar.items.items[1].hide();
} else if (record.data.type == '2') {
toolbar.items.items[0].hide();
}
};
var columnModelTree = [{
flex: 1,
xtype: "treecolumn",
dataIndex: "text",
}, {
width: 150,
xtype: "commandcolumn",
commands: gridCommand,
prepareToolbar: PrepareCommands
}];
</script>
</head>
<body>
<ext-viewport layout="Fit">
<items>
<ext-treePanel id="MyTreePanel" title="TreePanel" flex="1" frame="true" scrollable="true" margin="5" ui="Info">
<tbar>
<ext-toolbar>
<items>
<ext-button id="MyButton1" text="Reload from server">
<directEvents>
<click pageHandler="Button_Click" method="POST" success="App.MyTreePanel.store.setRoot(Ext.decode(response. responseText).result)">
<eventMask>
<ext-eventMask showMask="true" msg="Cargando..." />
</eventMask>
</click>
</directEvents>
</ext-button>
<ext-toolbarFill />
</items>
</ext-toolbar>
</tbar>
<store>
<ext-treeStore root="Model.Root">
<fields>
<ext-dataField name="type" />
</fields>
</ext-treeStore>
</store>
<customConfig>
<ext-add key="columns" value="columnModelTree" mode="Raw" />
</customConfig>
</ext-treePanel>
</items>
</ext-viewport>
</body>
cs:
using Ext.Net;
using Ext.Net.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
namespace Project.Pages {
public class ReloadTreePanelModel : PageModel {
public TreeNode Root = BuildTree();
public void OnGet() {
}
private static TreeNode BuildNode(string name, string type) {
TreeNode node = new TreeNode {
Text = name,
CustomConfig = new JsObject()
};
node.CustomConfig.Add("type", type);
return node;
}
private static TreeNode BuildTree() {
var root = new TreeNode() {
Text = "Node 1",
Children = new List<TreeNode> {
BuildNode("Node 1", "1"),
BuildNode("Node 2", "2"),
BuildNode("Node 3", "1"),
BuildNode("Node 4", "2"),
BuildNode("Node 5", "2"),
BuildNode("Node 6", "1"),
}
};
return root;
}
public IActionResult OnPostButton_Click(int Nivel) {
Root = new TreeNode() {
Text = "Node 1",
Children = new List<TreeNode> {
BuildNode("Node 1", "1"),
BuildNode("Node 2", "2"),
BuildNode("Node 3", "2"),
}
};
this.X().Toast("OK");
return this.Direct(Root);
}
}
}
@page
@model Project.Pages.ReloadTreePanelModel
@{
Layout = null;
}
<head>
<script type="text/javascript">
var gridCommand = [{
xtype: "button",
text: "button 1",
command: "commandbutton1",
}, {
xtype: "button",
text: "button 2",
command: "commandbutton2",
}];
var PrepareCommands = function (object, toolbar, rowIndex, record) {
if (record.data.depth == 0) {
toolbar.items.items[0].hide();
toolbar.items.items[1].hide();
}
if (record.data.type == '1') {
toolbar.items.items[1].hide();
} else if (record.data.type == '2') {
toolbar.items.items[0].hide();
}
};
var columnModelTree = [{
flex: 1,
xtype: "treecolumn",
dataIndex: "text",
}, {
width: 150,
xtype: "commandcolumn",
commands: gridCommand,
prepareToolbar: PrepareCommands
}];
</script>
</head>
<body>
<ext-viewport layout="Fit">
<items>
<ext-treePanel id="MyTreePanel" title="TreePanel" flex="1" frame="true" scrollable="true" margin="5" ui="Info">
<tbar>
<ext-toolbar>
<items>
<ext-button id="MyButton1" text="Reload from server">
<directEvents>
<click pageHandler="Button_Click" method="POST" success="App.MyTreePanel.store.setRoot(Ext.decode(response. responseText).result)">
<eventMask>
<ext-eventMask showMask="true" msg="Cargando..." />
</eventMask>
</click>
</directEvents>
</ext-button>
<ext-toolbarFill />
</items>
</ext-toolbar>
</tbar>
<store>
<ext-treeStore root="Model.Root">
<fields>
<ext-dataField name="type" />
</fields>
</ext-treeStore>
</store>
<customConfig>
<ext-add key="columns" value="columnModelTree" mode="Raw" />
</customConfig>
</ext-treePanel>
</items>
</ext-viewport>
</body>
cs:
using Ext.Net;
using Ext.Net.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;
namespace Project.Pages {
public class ReloadTreePanelModel : PageModel {
public TreeNode Root = BuildTree();
public void OnGet() {
}
private static TreeNode BuildNode(string name, string type) {
TreeNode node = new TreeNode {
Text = name,
CustomConfig = new JsObject()
};
node.CustomConfig.Add("type", type);
return node;
}
private static TreeNode BuildTree() {
var root = new TreeNode() {
Text = "Node 1",
Children = new List<TreeNode> {
BuildNode("Node 1", "1"),
BuildNode("Node 2", "2"),
BuildNode("Node 3", "1"),
BuildNode("Node 4", "2"),
BuildNode("Node 5", "2"),
BuildNode("Node 6", "1"),
}
};
return root;
}
public IActionResult OnPostButton_Click(int Nivel) {
Root = new TreeNode() {
Text = "Node 1",
Children = new List<TreeNode> {
BuildNode("Node 1", "1"),
BuildNode("Node 2", "2"),
BuildNode("Node 3", "2"),
}
};
this.X().Toast("OK");
return this.Direct(Root);
}
}
}