PDA

View Full Version : [CLOSED] DragDrop Grid to Tree



UnifyEducation
Sep 17, 2012, 9:33 AM
Hi,

I tried your example at http://examples2.ext.net/#/DragDrop/Grid/Grid_to_Tree/
But when I drag a node back to the grid, I have nothing in the column "price".
Another question is how can I call the ajax request to server with the node values. Because I want to get nodeID, nodeText and parentNode ID, parrentNode Text.
Thank you in advance
Here is my test:




<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
private object[] TestData
{
get
{
DateTime now = DateTime.Now;

return new object[]
{
new object[] { "3m Co", 71.72, 0.02, 0.03, now },
new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, now },
new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, now },
new object[] { "American Express Company", 52.55, 0.01, 0.02, now },
new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, now },
new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, now },
new object[] { "Boeing Co.", 75.43, 0.53, 0.71, now },
new object[] { "Caterpillar Inc.", 67.27, 0.92, 1.39, now },
new object[] { "Citigroup, Inc.", 49.37, 0.02, 0.04, now },
new object[] { "E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28, now },
new object[] { "Exxon Mobil Corp", 68.1, -0.43, -0.64, now },
new object[] { "General Electric Company", 34.14, -0.08, -0.23, now },
new object[] { "General Motors Corporation", 30.27, 1.09, 3.74, now },
new object[] { "Hewlett-Packard Co.", 36.53, -0.03, -0.08, now },
new object[] { "Honeywell Intl Inc", 38.77, 0.05, 0.13, now },
new object[] { "Intel Corporation", 19.88, 0.31, 1.58, now },
new object[] { "International Business Machines", 81.41, 0.44, 0.54, now },
new object[] { "Johnson & Johnson", 64.72, 0.06, 0.09, now },
new object[] { "JP Morgan & Chase & Co", 45.73, 0.07, 0.15, now },
new object[] { "McDonald\"s Corporation", 36.76, 0.86, 2.40, now },
new object[] { "Merck & Co., Inc.", 40.96, 0.41, 1.01, now },
new object[] { "Microsoft Corporation", 25.84, 0.14, 0.54, now },
new object[] { "Pfizer Inc", 27.96, 0.4, 1.45, now },
new object[] { "The Coca-Cola Company", 45.07, 0.26, 0.58, now },
new object[] { "The Home Depot, Inc.", 34.64, 0.35, 1.02, now },
new object[] { "The Procter & Gamble Company", 61.91, 0.01, 0.02, now },
new object[] { "United Technologies Corporation", 63.26, 0.55, 0.88, now },
new object[] { "Verizon Communications", 35.57, 0.39, 1.11, now },
new object[] { "Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, now }
};
}
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Store1.DataSource = this.TestData;
this.Store1.DataBind();
}
}
</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title>Drag and Drop from GridPanel to TreePanel - Ext.NET Examples</title>

<link href="/resources/css/examples.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
var beforerecorddrop = function (node, data, overModel, dropPosition, dropFn) {
if (Ext.isArray(data.records)) {
var records = data.records,
rec;

data.records = [];
var rec;

for (var i = 0; i < records.length; i++) {
rec = records[i];

data.records.push({
text: rec.get("company"),
leaf: true,
price: rec.get("price"),
change: rec.get("change"),
pctChange: rec.get("pctChange"),
qtip: rec.get("lastChange")
});

rec.stores[0].remove(rec);

Ext.Ajax.request({
url: '/Test/UpdateTree/',
params: {
textContent: node.textContent,
parentNode: node.parentNode.textContent
}
});
}

return true;
}
};

var beforenodedrop = function (node, data, overModel, dropPosition, dropFn) {
if (Ext.isArray(data.records)) {
var records = data.records,
rec;

data.records = [];
var rec;

for (var i = 0; i < records.length; i++) {
rec = records[i];

data.records.push(this.store.createModel({
company: rec.get("text"),
price: rec.get("price"),
change: rec.get("change"),
pctChange: rec.get("pctChange"),
lastChange: rec.get("qtip")
}));

rec.remove(true);
}

return true;
}
};
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Panel ID="Panel1"
runat="server"
Width="700"
Height="400"
Layout="BorderLayout">
<Items>
<ext:GridPanel ID="GridPanel1"
runat="server"
Region="Center"
Title="Grid"
MultiSelect="true"
Margins="5 0 5 5">
<Store>
<ext:Store
ID="Store1"
runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="company" />
<ext:ModelField Name="price" />
<ext:ModelField Name="change" Type="Float" />
<ext:ModelField Name="pctChange" Type="Float" />
<ext:ModelField Name="lastChange" Type="Date"/>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1"
runat="server"
Text="Company"
Sortable="true"
DataIndex="company"
Flex="1"
/>
<ext:Column ID="Column2"
runat="server"
Text="Price"
Width="75"
Sortable="true"
DataIndex="price">
</ext:Column>
</Columns>
</ColumnModel>
<View>
<ext:GridView ID="GridView1" runat="server">
<Plugins>
<ext:GridDragDrop ID="GridDragDrop1" runat="server" DragGroup="grid2tree" DropGroup="tree2grid" />
</Plugins>
<Listeners>
<BeforeDrop Fn="beforenodedrop" />
</Listeners>
</ext:GridView>
</View>
</ext:GridPanel>

<ext:TreePanel ID="TreePanel1"
runat="server"
Region="East"
Width="300"
Title="Tree"
AutoScroll="true"
Margins="5 5 5 0"
Split="true">
<Root>
<ext:Node Text="Root" Expanded="true" AllowDrag="false">
<Children>
<ext:Node Text="Folder 1" Qtip="Rows dropped here will be appended to the folder" AllowDrag="false">
<Children>
<ext:Node Text="Subleaf 1" Qtip="Subleaf 1 Quick Tip" Leaf="true" AllowDrag="false"/>
</Children>
</ext:Node>

<ext:Node Text="Folder 2" Qtip="Rows dropped here will be appended to the folder" AllowDrag="false">
<Children>
<ext:Node Text="Subleaf 2" Qtip="Subleaf 2 Quick Tip" Leaf="true" AllowDrag="false"/>
</Children>
</ext:Node>

<ext:Node Text="Leaf 1" Qtip="Leaf 1 Quick Tip" Leaf="true" AllowDrag="false" />
</Children>
</ext:Node>
</Root>
<View>
<ext:TreeView ID="TreeView1" runat="server">
<Plugins>
<ext:TreeViewDragDrop ID="TreeViewDragDrop1" runat="server" DragGroup="tree2grid" DropGroup="grid2tree" />
</Plugins>
<Listeners>
<BeforeDrop Fn="beforerecorddrop" />
</Listeners>
</ext:TreeView>
</View>
</ext:TreePanel>
</Items>
</ext:Panel>
</form>
</body>
</html>

Daniil
Sep 17, 2012, 11:01 AM
Hi,



But when I drag a node back to the grid, I have nothing in the column "price".


I think you should add these things. i.e. "price" and others, to the TreePanel Fields collection.



Another question is how can I call the ajax request to server with the node values. Because I want to get nodeID, nodeText and parentNode ID, parrentNode Text.


I would suggest to use Ext.net.DirectMethod.request.
http://examples2.ext.net/#/Events/DirectMethods/WebService/

UnifyEducation
Sep 17, 2012, 1:16 PM
Hi,

I would suggest to use Ext.net.DirectMethod.request.
http://examples2.ext.net/#/Events/DirectMethods/WebService/

Hi, Thanks for your help. But which function to get nodeID, nodeText and parentNode ID, parrentNode Text?



Ext.net.DirectMethod.request({
url: '/Services/GroupManagement.asmx/UpdateGroup',
cleanRequest: true,
json: true,
params: {
node: node.text

},
success : function (result) {
Ext.Msg.alert("Json Message", result);
}
});


I tried to use all Node Object Properties from http://www.w3schools.com/dom/dom_node.asp but it doesn't work

Daniil
Sep 17, 2012, 1:28 PM
But which function to get nodeID, nodeText and parentNode ID, parrentNode Text?

Please use:

node.getId();
node.getText();
node.parentNode().getId();
node.parentNode.getText();



I tried to use all Node Object Properties from http://www.w3schools.com/dom/dom_node.asp but it doesn't work

DOM node and TreePanel nodes are not the same. The last ones are JavaScript class instances.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.NodeInterface

This class is used as a set of methods that are applied to the prototype of a Model to decorate it with a Node API.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model

UnifyEducation
Sep 17, 2012, 2:13 PM
Hi,

I got the following error: Uncaught TypeError: Object #<HTMLTableRowElement> has no method 'getId'



Ext.net.DirectMethod.request({
url: '/Services/GroupManagement.asmx/UpdateGroup',
cleanRequest: true,
json: true,
params: {
nodeId: node.getId()
},
success : function (result) {
Ext.Msg.alert("Json Message", result);
}
});

Daniil
Sep 17, 2012, 4:01 PM
I think you should use "rec" instead of "node".

UnifyEducation
Sep 18, 2012, 9:51 AM
I think you should use "rec" instead of "node".

Hi, the "rec" for get values from items that I drag.
But I want to get the node value that that I drop items in (it is already exist in the tree)

Daniil
Sep 18, 2012, 12:12 PM
Well, the "rec" variable within the "beforenodedrop" function represents a TreePanel node.

There is some misunderstanding between us.

Now I guess, you need this information for a node which is created after dropping a grid record to the tree. Am I understanding correctly now?

UnifyEducation
Sep 19, 2012, 4:45 PM
Well, the "rec" variable within the "beforenodedrop" function represents a TreePanel node.

There is some misunderstanding between us.

Now I guess, you need this information for a node which is created after dropping a grid record to the tree. Am I understanding correctly now?

No, I need a node that I drop item to.

For example: I have a tree
-Node1
---Child1
---Child2
-Node2
---Child3
---Child4

When I drop a grid record to the node "Child3", I need information of "Child3" and its parent Node ("Node2")
Could you tell me how to get them? I'm not very good at javascript

Daniil
Sep 19, 2012, 5:31 PM
Thank you for clarification.

Here is a solution.

Example

var beforerecorddrop = function (node, data, overModel, dropPosition, dropFn) {
var treeNode = this.getRecord(node);
text = treeNode.get("text"),
id = treeNode.getId(),
parentText = treeNode.parentNode.get("text"),
parentId = treeNode.parentNode.getId();

alert(text + " " + id + " " + parentText + " " + parentId);

/* the rest code */
};

UnifyEducation
Sep 21, 2012, 11:16 AM
Thanks for your help.

And when I drop a node to a gridpanel, how I can get the parent nodes
For example: I have a tree

-Node1
---Child1
---Child2
-Node2
---Child3
------Child3.1
------Child3.2
---Child4

When I drop node "Child3.1" to a gridpanel, how I can get the parent nodes ("Child3" and "Node2")
It is so great if you can give me a javascript example.
Thanks in advance


Thank you for clarification.

Here is a solution.

Example

var beforerecorddrop = function (node, data, overModel, dropPosition, dropFn) {
var treeNode = this.getRecord(node);
text = treeNode.get("text"),
id = treeNode.getId(),
parentText = treeNode.parentNode.get("text"),
parentId = treeNode.parentNode.getId();

alert(text + " " + id + " " + parentText + " " + parentId);

/* the rest code */
};

Daniil
Sep 21, 2012, 12:29 PM
In this case, the "rec" is a tree node within the "beforenodedrop" function.

So, the answer is within the posts #4 and #6.