FineUI 官方论坛
标题:
Tree绑定datatable,加载数据量大的问题?
[打印本页]
作者:
在路上
时间:
2013-5-17 08:38
标题:
Tree绑定datatable,加载数据量大的问题?
Tree加载datatable数据量大,加载很慢,有延迟加载的办法吗???
作者:
spmouse
时间:
2013-5-17 09:54
有例子啊
http://fineui.com/demo/#/demo/tree/tree_ajax.aspx
作者:
在路上
时间:
2013-5-17 10:48
我的是datatable转换的
作者:
spmouse
时间:
2013-5-20 16:00
菜鸟程序员表示2天才搞定...
CS页面:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
private void LoadData()
{
DataSet ds = new DataSet();
ds.Tables.Add(CreateDataTable());
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["ParentId"]);
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row.IsNull("ParentId"))
{
TreeNode node = new TreeNode();
node.Text = row["Text"].ToString();
node.NodeID = row["Id"].ToString();
node.Leaf = (bool)row["isLeaf"];
Tree1.Nodes.Add(node);
}
}
}
private void ResolveSubTree(DataRow dataRow, TreeNode treeNode)
{
DataRow[] rows = dataRow.GetChildRows("TreeRelation");
if (rows.Length > 0)
{
treeNode.Expanded = true;
foreach (DataRow row in rows)
{
TreeNode node = new TreeNode();
node.Text = row["Text"].ToString();
treeNode.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
protected void Tree1_NodeExpand(object sender, FineUI.TreeExpandEventArgs e)
{
DynamicAppendNode(e.Node);
}
private void DynamicAppendNode(TreeNode parentNode)
{
parentNode.Expanded = true;
TreeNode node = null;
DataSet ds = new DataSet();
ds.Tables.Add(CreateDataTable());
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["ParentId"]);
foreach (DataRow row in ds.Tables[0].Rows)
{
string parentid = row["ParentId"].ToString();
if (parentid == parentNode.NodeID)
{
node = new TreeNode();
node.Text = row["Text"].ToString();
node.NodeID = row["Id"].ToString();
node.Leaf = (bool)row["isLeaf"];
parentNode.Nodes.Add(node);
}
}
}
#region CreateDataTable
private DataTable CreateDataTable()
{
DataTable table = new DataTable();
DataColumn column1 = new DataColumn("Id", typeof(string));
DataColumn column2 = new DataColumn("Text", typeof(String));
DataColumn column3 = new DataColumn("ParentId", typeof(string));
DataColumn column4 = new DataColumn("isLeaf", typeof(bool));
table.Columns.Add(column1);
table.Columns.Add(column2);
table.Columns.Add(column3);
table.Columns.Add(column4);
DataRow row = table.NewRow();
row = table.NewRow();
row[0] = "xinjiang";
row[1] = "新疆";
row[2] = DBNull.Value;
row[3] = false;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "wulumuqi";
row[1] = "乌鲁木齐";
row[2] = "xinjiang";
row[3] = false;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "changji";
row[1] = "昌吉";
row[2] = "xinjiang";
row[3] = false;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "tianshanqu";
row[1] = "天山区";
row[2] = "wulumuqi";
row[3] = true;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "shayibakequ";
row[1] = "沙依巴克区";
row[2] = "wulumuqi";
row[3] = true;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "wujiaqu";
row[1] = "五家渠";
row[2] = "changji";
row[3] = true;
table.Rows.Add(row);
row = table.NewRow();
row[0] = "mulei";
row[1] = "木垒";
row[2] = "changji";
row[3] = true;
table.Rows.Add(row);
return table;
}
#endregion
复制代码
aspx页面:
<body>
<form id="form1" runat="server">
<x:PageManager ID="PageManager1" runat="server" />
<x:Tree ID="Tree1" Width="500px" EnableArrows="true" EnableLines="false" ShowHeader="true" OnNodeExpand="Tree1_NodeExpand"
Title="树控件" runat="server" AutoLeafIdentification="false">
</x:Tree>
</form>
</body>
复制代码
作者:
spmouse
时间:
2013-5-20 16:05
ResolveSubTree这个函数是直接绑定tadatable的示例里带的,这里不用,忘去掉了
作者:
icelemon
时间:
2014-8-26 00:05
节点定义的三个属性,id,name,parentid
如是代码添加关系时提示并非所有节点都有父节点!求解决办法
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4