PDA

View Full Version : [CLOSED] Gridpanel: How to insert new row in the gridpanel store



AdminAISN
Nov 07, 2013, 9:11 AM
I have a gridpanel whiwch is filled via its related store.
I want to add new row to the store so that it will be shown in the gridpanel.
Someone can help Me?


[DirectMethod]
protected void treePanelChecked_Changed(object sender, DirectEventArgs e)
{
List<SubmittedNode> selectedNode= ((Ext.Net.TreeSelectionModel)(TreePanel1.GetSelect ionModel())).SelectedNodes;
if (selectedNode != null && selectedNode.Count > 0)
{
SubmittedNode currentNode= selectedNode[0];
DTO grd = Lst.FirstOrDefault(g => g.Id.ToString() == currentNode.NodeID);
if (!currentNode.Checked)
{
Store grdstore=GridPanel1.GetStore();
grdstore.Insert(0, grd);
grdstore.DataBind();
}
}

mtsig
Nov 07, 2013, 9:19 AM
<ext:Store ID="store_act" runat="server" AutoSync="false">
<Model>
<ext:Model ID="model_act" runat="server" IDProperty="ACV_ID" Name="ACT">
<Fields>
<ext:ModelField Name="ACV_ID" Type="Int" />
<ext:ModelField Name="ACV_DATE" Type="Date" />
<ext:ModelField Name="ACV_HOURS" Type="Float"/>

</Fields>
</ext:Model>
</Model>
</ext:Store>


In Javascript


var newrow = new ACT({ ACV_DATE: new Date(), ACV_HOURS: 15 });
newrow.phantom = true;
App.store_act.insert(0, newrow);

AdminAISN
Nov 07, 2013, 9:23 AM
<ext:Store ID="store_act" runat="server" AutoSync="false">
<Model>
<ext:Model ID="model_act" runat="server" IDProperty="ACV_ID" Name="ACT">
<Fields>
<ext:ModelField Name="ACV_ID" Type="Int" />
<ext:ModelField Name="ACV_DATE" Type="Date" />
<ext:ModelField Name="ACV_HOURS" Type="Float"/>

</Fields>
</ext:Model>
</Model>
</ext:Store>


In Javascript


var newrow = new ACT({ ACV_DATE: new Date(), ACV_HOURS: 15 });
newrow.phantom = true;
App.store_act.insert(0, newrow);

I do it in codebehind using directEvent
Is there a solution using codebehind C# Code?

Daniil
Nov 07, 2013, 10:44 AM
Hi @AdminAISN,

Welcome to the Ext.NET forum!

I think you should remove this:

grdstore.DataBind();

It is uses a Store's DataSource which you are not setting up. So, the Store is bound with no data erasing an added record by the Insert call.

@mtsig, thank you for answering! Much appreciated.

AdminAISN
Nov 07, 2013, 5:39 PM
I have a gridpanel whiwch is filled via its related store.
I want to add new row to the store so that it will be shown in the gridpanel.
Someone can help Me?


[DirectMethod]
protected void treePanelChecked_Changed(object sender, DirectEventArgs e)
{
List<SubmittedNode> selectedNode= ((Ext.Net.TreeSelectionModel)(TreePanel1.GetSelect ionModel())).SelectedNodes;
if (selectedNode != null && selectedNode.Count > 0)
{
SubmittedNode currentNode= selectedNode[0];
DTO grd = Lst.FirstOrDefault(g => g.Id.ToString() == currentNode.NodeID);
if (!currentNode.Checked)
{
Store grdstore=GridPanel1.GetStore();
grdstore.Insert(0, grd);
grdstore.DataBind();
}
}

I tried but unfortunetly it doesn't work. I was obliged to rebuild the datasource. Perhaps somebody will gie me an help.
Thx.

Baidaly
Nov 07, 2013, 10:05 PM
Hello!

Couldn't reproduce with the following sample:


<%@ 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)
{
this.Store1.DataSource = this.Data;
this.Store1.DataBind();
}
}

protected void AddRecord(object sender, DirectEventArgs e)
{
Store1.Insert(0, new { company = "3m Co", price = 71.72, change = 0.02, pctChange = 0.03, lastChange = "9/1 12:00am" });
}

private object[] Data
{
get
{
return new object[]
{
new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, "9/1 12:00am" },
new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, "9/1 12:00am" },
new object[] { "American Express Company", 52.55, 0.01, 0.02, "9/1 12:00am" },
new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, "9/1 12:00am" },
new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, "9/1 12:00am" },
new object[] { "Boeing Co.", 75.43, 0.53, 0.71, "9/1 12:00am" }
};
}
}
</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<h1>Simple Array Grid</h1>

<ext:GridPanel
ID="GridPanel1"
runat="server"
Title="Array Grid"
Width="600"
Height="350">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="company" />
<ext:ModelField Name="price" Type="Float" />
<ext:ModelField Name="change" Type="Float" />
<ext:ModelField Name="pctChange" Type="Float" />
<ext:ModelField Name="lastChange" Type="Date" DateFormat="M/d hh:mmtt" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="Column1" runat="server" Text="Company" DataIndex="company" Flex="1" />
<ext:Column ID="Column2" runat="server" Text="Price" DataIndex="price">
</ext:Column>
<ext:Column ID="Column3" runat="server" Text="Change" DataIndex="change">
</ext:Column>
<ext:Column ID="Column4" runat="server" Text="Change" DataIndex="pctChange">
</ext:Column>
<ext:DateColumn ID="DateColumn1" runat="server" Text="Last Updated" DataIndex="lastChange" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
</SelectionModel>
<BottomBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:Button Text="Add a record">
<DirectEvents>
<Click OnEvent="AddRecord" />
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</BottomBar>
</ext:GridPanel>
</body>
</html>

If it doesn't help please provide sample to reproduce according to these recommendations:
http://forums.ext.net/showthread.php?3440
http://forums.ext.net/showthread.php?10205