Originally Posted by
Daniil
Even better would be the following solution:
1. Use
EnableRowBody="true"
and GetRowClass to show a data.
The same as I did.
2. Use RowExpander with Component for adding comments.
Not so easy. RowExpander defines its own GetRowClass, so it's not possible to set up your one.
Finally, I can suggest the following solution. Again - a partial solotuion, just a start point for you. Now it doesn't add comments, though it should not be a problem.
Example
<%@ 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 object[] { "test1", new string[] { "comment1", "comment2" } },
new object[] { "test2", new string[] { } },
new object[] { "test3", new string[] { "comment1", "comment2", "comment3" } },
};
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 Example</title>
<script type="text/javascript">
var rowBodySelector = "table.x-grid3-row-table > tbody > tr:nth(2) div.x-grid3-row-body";
var getRowClass = function (record, index, rowParams, store) {
var rowBody = "",
comments = record.get("comments");
Ext.each(comments, function (c) {
rowBody += "<p>" + c + "</p>";
});
rowParams.body = rowBody;
};
var onCommand = function (command, record, rowIndex, colIndex) {
var grid = this,
panel,
row,
body;
if (command === "addComment") {
panel = grid.bin;
row = grid.getView().getRow(rowIndex);
body = Ext.DomQuery.selectNode("table.x-grid3-row-table > tbody > tr:nth(2) div.x-grid3-row-body", row)
if (panel.rendered) {
Ext.fly(body).appendChild(panel.getEl());
} else {
panel.render(body);
}
panel.get(0).clear();
panel.show();
}
};
var onAdd = function (btn) {
// some code to add a new comment
btn.ownerCt.hide();
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Bin>
<ext:Panel
runat="server"
Height="22"
Layout="HBoxLayout"
Border="false">
<Items>
<ext:TextField runat="server" Flex="1" />
<ext:Button runat="server" Text="Submit" Width="50">
<Listeners>
<Click Fn="onAdd" />
</Listeners>
</ext:Button>
</Items>
</ext:Panel>
</Bin>
<Store>
<ext:Store runat="server">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="name" />
<ext:RecordField Name="comments" IsComplex="true" />
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column Header="Name" DataIndex="name" />
<ext:ImageCommandColumn Width="25">
<Commands>
<ext:ImageCommand CommandName="addComment" Icon="Add" />
</Commands>
</ext:ImageCommandColumn>
</Columns>
</ColumnModel>
<View>
<ext:GridView runat="server" EnableRowBody="true">
<GetRowClass Fn="getRowClass" />
</ext:GridView>
</View>
<Listeners>
<Command Fn="onCommand"/>
</Listeners>
</ext:GridPanel>
</form>
</body>
</html>