PDA

View Full Version : [CLOSED] Dynamic Columns and Fields MVC application



romeu
Feb 25, 2012, 5:45 PM
I need create dynamic Collumns in GridPanel and Fields in Store.

My application is MVC.

Can you send me one example for this, please ?


Thank's

Daniil
Feb 27, 2012, 11:20 AM
Hi,

I can suggest the following solution.

Example View

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

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

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new
{
test = "test1"
},
new
{
test = "test2"
}
};
store.DataBind();
}
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.Net.MVC Example</title>

<script type="text/javascript">
var onSuccess = function (grid, result) {
var store = grid.getStore();

grid.addColumn(Ext.create("Ext.grid.column.Column", Ext.decode(result.column)));
store.addField(result.field);

//test
store.loadData([{
test : "test1",
someDataIndex : "new1"
}, {
test : "test2",
someDataIndex : "new2"
}]);
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test" DataIndex="test" />
</Columns>
</ColumnModel>
</ext:GridPanel>
<ext:Button runat="server" Text="Add column">
<DirectEvents>
<Click Url="/Test/AddColumn" Success="onSuccess(#{GridPanel1}, result.result);" />
</DirectEvents>
</ext:Button>
</body>
</html>

Examples Controller Action

public ActionResult AddColumn()
{
Column c = new Column()
{
Text = "New",
DataIndex = "someDataIndex"
};

AjaxResult r = new AjaxResult();
r.Result = new
{
column = c.ToConfig(),
field = "someDataIndex"
};

return r;
}

romeu
Feb 27, 2012, 2:30 PM
It seems you do not recognize the type <Model>.

Displays this error message:




Server Error in '/ athenasx' Application.
-------------------------------------------------- ------------------------------


Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review The Following specific parse error details and modify your source file appropriately.

Parser Error Message: Type 'Ext.Net.Store' does not have a public property named 'Model'.

Source Error:





Line 330: <STORE>
Line 331 <ext:Store runat="server" AutoLoad="false" IgnoreExtraFields="false">
Line 332: <Model>
Line 333: <ext:Model AutoDataBind="true" IDProperty="CODIGO" Root="data" TotalProperty="total">
Line 334: <FIELDS>

Source File: / athenasx / Areas / Administrative / Views / ProcuraRegistro / index.aspx Line: 332

Daniil
Feb 27, 2012, 2:33 PM
Do you use Ext.NET v1, not v2?

romeu
Feb 27, 2012, 2:41 PM
I use version 1.0

romeu
Feb 27, 2012, 2:42 PM
Can I already use version 2.0 in my application ?

Daniil
Feb 27, 2012, 2:53 PM
I use version 1.0

Please post Ext.NET v1 related technical support questions on the Premium Help 1.x forum, not on the 2.x one.

Daniil
Feb 27, 2012, 2:54 PM
Can I already use version 2.0 in my application ?

It would be best to start a new forum thread for this question since it's not related to the initial topic.

romeu
Feb 27, 2012, 6:31 PM
Sorry, i creat a new post.


Can you close this.

romeu
Feb 27, 2012, 7:00 PM
I created another, you can close this please.

thank you

Daniil
Feb 27, 2012, 7:08 PM
For someone how might be interested.

See the following thread for this problem using Ext.NET v1.
http://forums.ext.net/showthread.php?17511