Hi,
I have tested the client side api of your FlyTreeView and it does not work as expected.
The client side method node.setText(text); does not change node text if you change more than one node at a time...
eg. foreach(node) { node.setText(...); }
There should be a postback for all text nodes to be updated, wich is really anoying since it is a client side api I'm working with.
Please find below the code that I used
To reproduce, run the web site,
Click flyTreeView_LoadCount
Root(x) become Root(0) .. ok
Root(x) does not change .. bug
Sometime it works, sometimes it doesn't.
Open Root(x)
Click flyTreeView_LoadCount
Category 1 (x) become Category 1 (0) .. ok
Category 1 (x) does not change .. bug
Sometime it works, sometimes it doesn't.
This one never work.
Open Category 1 (x)
Click flyTreeView_LoadCount
root (0) ok
category 1 (0) ok
category 2 (0) ok
category 103 (0) ok
category 204 (0) ok
category 305 (0) ok
category 406 (0) ok
category 507 (0) ok
category 608 (0) ok
category 709 (0) ok
category 810 (0) ok
category 911 (0) ok
category 1012 (0) ok
category 1113 (0) ok
category 1214 (0) ok
category 1315 (0) ok
category 1416 (x) bug
category 1517 (x) bug
category 1618 (x) bug
category 1719 (x) bug
category 1820 (x) bug
category 1921 (x) bug
category 2022 (x) bug
category 2123 (x) bug
category 2224 (x) bug
and so on...
Thanks for your feedback.
Regards
Luc
-------- Default.aspx
--%>
flyTreeView_loadCount
--%>
var treeview;
var lastX = /\(x\)$/g;
lastX.compile(lastX);
$j(document).ready(jquery_ready);
function jquery_ready() {
log('jquery_ready');
}
function flyTreeView_loadCount() {
log('flyTreeView_loadCount');
var nodelist = treeview.findAll(function(node) {
return (node.getAttribute("CategoryTreeListControlDisplayCount") == 'true'
&& node.getText().match(lastX)
);
});
log('nodes: ' + nodelist.length);
Array.forEach(nodelist, flyTreeView_setCount);
// $j.each(nodelist, flyTreeView_setCount);
}
function flyTreeView_setCount(node) {
log('flyTreeView_setCount: '+ node.getText());
var text = node.getText();
text = text.replace(lastX, '(0)');
node.setText(text);
}
function flyTreeView_onInitialized(sender) {
log('flyTreeView_onInitialized');
treeview = sender;
}
function flyTreeView_onNodeEvent(sender, node, eventType) {
log('flyTreeView_onNodeEvent');
}
function flyTreeView_onSelectedNodeChanged(sender, node, eventType) {
log('flyTreeView_onSelectedNodeChanged');
}
function flyTreeView_onSelectedNodeChanging(sender, node, eventType) {
log('flyTreeView_onSelectedNodeChanging');
}
// ===========================================================
var logElement;
var logNum = 0;
function log(message, category) {
if (category) message = category + ": " + message;
if (!logElement)
logElement = document.getElementById("eventsLog");
var message = ++logNum + ") " + message;
var divMessage = document.createElement("DIV");
divMessage.innerHTML = escapeHtml(message);
divMessage.style.whiteSpace = "nowrap";
logElement.insertBefore(divMessage, logElement.firstChild);
}
function escapeHtml(html) {
html = html.replace(//g, ">");
html = html.replace(/\n/g, "
");
return html;
}
/*]]>*/
// -->
---- Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NineRays.WebControls;
using System.Threading;
namespace FlyTreeViewWebsite {
public partial class _Default : System.Web.UI.Page {
public class Node {
public string Name;
private readonly int _id;
public int Id {
get {
return this._id;
}
}
public Node[] Children;
public Node() {
this._id = NextKey;
Node._ids.Add(this._id, this);
}
private static int _nodekey = 0;
private static int NextKey {
get {
return _nodekey++;
}
}
private static Dictionary _ids = new Dictionary();
public static Node FindById(int id) {
return _ids[id];
}
}
private static Node RootNode = new Node() {
Name = "root"
};
private static int[] defs = { 1, 100, 100 };
static _Default() {
Node node = RootNode;
int level = 0;
RecursiveLoad(node, level);
}
private static void RecursiveLoad(Node parent, int level) {
if (level >= defs.Length) {
return;
}
int i = defs[level];
if (i <= 0) {
return;
}
parent.Children = new Node[i];
for (int j = 0; j < i; j++) {
Node child = new Node();
child.Name = string.Format("category {0}", child.Id);
parent.Children[j] = child;
RecursiveLoad(child, level+1);
}
}
protected void Page_Init(object sender, EventArgs e) {
if (!Page.IsPostBack) {
this.DataBind();
}
}
protected void Page_Load(object sender, EventArgs e) {
this.RegisterJavascript();
}
public override void DataBind() {
base.DataBind();
this.__treeView.Nodes.Clear();
FlyTreeNode rootNode = this.CreateNode(RootNode);
this.__treeView.Nodes.Add(rootNode);
}
protected void Page_PreRender(object sender, EventArgs e) {
//this.ExpandSelectedCategory();
}
private void ExpandSelectedCategory() {
this.__treeView.ExpandLevel = 0;
this.__treeView.FindAll(
node => {
node.Expanded = null;
return false;
}
);
string[] paths = { "/root", "/root/category1", "/root/category1/sub-category1" };
int nbPaths = paths.Length;
foreach (string path in paths) {
FlyTreeNode node = this.__treeView.FindByPath(path);
if (null != node) {
node.Expand();
if (node.Path == paths[nbPaths - 1]) {
node.Selected = true;
}
}
}
}
protected void TreeView_NodeChanged(object sender, EventArgs e) {
Console.WriteLine("");
}
protected void TreeView_TreeNodePopulate(object sender, FlyTreeNodeEventArgs e) {
Thread.Sleep(1000);
FlyTreeView tree = (FlyTreeView)sender;
FlyTreeNode flnode = (FlyTreeNode)e.Node;
Node node = Node.FindById(int.Parse(flnode.Value));
foreach (Node child in node.Children) {
FlyTreeNode flChild = this.CreateNode(child);
flnode.ChildNodes.Add(flChild);
}
}
private void RegisterJavascript() {
string[] libs = new string[] { "jquery-1.4.min", "jquery-noconflict" };
foreach (string lib in libs) {
string clientUrl = ResolveClientUrl(string.Format("~/lib/{0}.js", lib));
Page.ClientScript.RegisterClientScriptInclude(lib, clientUrl);
}
}
private FlyTreeNode CreateNode(Node node) {
string text = string.Format("{0} (x)", node.Name);
FlyTreeNode flnode = new FlyTreeNode();
flnode.Value = node.Id.ToString();
flnode.PopulateNodesOnDemand = (node.Children != null);
flnode.Text = text;
flnode.Attributes["CategoryTreeListControlDisplayCount"] = "true";
return flnode;
}
protected void TreeView_PreRender(object sender, EventArgs e) {
}
}
}