PDA

View Full Version : [CLOSED] ComponentColumn editor does not save values



marco.morreale
Jan 16, 2013, 10:25 AM
Hi,
I am trying to use example "http://examples2.ext.net/#/GridPanel/ComponentColumn/Editor/" to create a dynamyc list of controls inside a form.

I set a List as a datasource for the gridpanel.

My problem occurs when I add a new row after editing a row: all previous values are cleared.

I thought component column automatically commits and save values to the list.

How can I persist values set in the rows cells?

Thanks in advance
M






public partial class Ticket_Details : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!X.IsAjaxRequest)
{
// on load I create the first row, it works
dataSource = new List<Intervento>();
Intervento intervento = new Intervento();

dataSource.Add(intervento);

this.stRigaListino.DataSource = DataSource;

this.stRigaListino.DataBind();
}

}

protected void btnAddService_Click(object sender, DirectEventArgs e)
{

// First I save values in existing rows
this.stRigaListino.CommitChanges();

// Then I put a new record in the list
Intervento intervento = new Intervento();
dataSource.Add(intervento);

// Then databind the grid but old values are cleared!!
this.stRigaListino.DataSource = DataSource;

this.stRigaListino.DataBind();
}

private static List<Intervento> dataSource;

public static List<Intervento> DataSource
{
get
{
return dataSource;
}
}


}

public class Intervento
{
public string ID
{
get;
set;
}
public string Descrizione
{
get;
set;
}
public string MarcaId
{
get;
set;
}
public string Modello
{
get;
set;
}
public bool RAEE
{
get;
set;
}
public bool Trasporto
{
get;
set;
}
public bool DisponibilitaMerce
{
get;
set;
}
public DateTime? DataDisponibilitaMerce
{
get;
set;
}
public bool MagazzinoRitiro
{
get;
set;
}
}

Baidaly
Jan 16, 2013, 1:09 PM
Hello!

Can you provide full and simplified sample (with markup) to reproduce your problem?

http://forums.ext.net/showthread.php?10205-More-Information-Required

marco.morreale
Jan 17, 2013, 12:42 PM
Hi,
here is the running example.

Steps to reproduce:
1) edit a value
2) click "add Row" button

Error: editings at step 1 are lost.

Thanks in advance.
Marco Morreale





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

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

<script runat="server">

public static List<object> myList;

protected void Page_Load(object sender, EventArgs e)
{

if (!X.IsAjaxRequest)
{
myList = new List<object>();

for (int i = 1; i < 10; i++)
{
myList.Add(new object[] { i, i, "Text " + i, DateTime.Now.Date });
}

this.Store1.DataSource = myList;

this.Store1.DataBind();
}
}

protected void btnAddService_Click(object sender, DirectEventArgs e)
{
this.Store1.CommitChanges();

Intervento intervento = new Intervento();
myList.Add(new object[] { 11, 11, "Text 11", DateTime.Now.Date });

this.Store1.DataSource = myList;

this.Store1.DataBind();
}

</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>ComponentColumn Editor - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<h1>ComponentColumn as Editor</h1>

<ext:GridPanel
runat="server"
Title="ComponentColumn Editor"
Width="600"
Height="300">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="IntField" Type="Int" />
<ext:ModelField Name="ComboField" Type="Int" />
<ext:ModelField Name="TextField" Type="String" />
<ext:ModelField Name="DateField" Type="Date" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:ComponentColumn
runat="server"
Editor="true"
DataIndex="IntField"
Flex="1"
Text="Integer">
<Component>
<ext:NumberField runat="server" />
</Component>
</ext:ComponentColumn>

<ext:ComponentColumn
runat="server"
Editor="true"
DataIndex="ComboField"
Flex="1"
Text="ComboBox">
<Component>
<ext:ComboBox runat="server">
<Items>
<ext:ListItem Text="Item 1" Value="1" Mode="Raw" />
<ext:ListItem Text="Item 2" Value="2" Mode="Raw" />
<ext:ListItem Text="Item 3" Value="3" Mode="Raw" />
<ext:ListItem Text="Item 4" Value="4" Mode="Raw" />
<ext:ListItem Text="Item 5" Value="5" Mode="Raw" />
<ext:ListItem Text="Item 6" Value="6" Mode="Raw" />
<ext:ListItem Text="Item 7" Value="7" Mode="Raw" />
<ext:ListItem Text="Item 8" Value="8" Mode="Raw" />
<ext:ListItem Text="Item 9" Value="9" Mode="Raw" />
</Items>
</ext:ComboBox>
</Component>
</ext:ComponentColumn>

<ext:ComponentColumn
runat="server"
Editor="true"
DataIndex="TextField"
Flex="1"
Text="Text">
<Component>
<ext:TextField runat="server" />
</Component>
</ext:ComponentColumn>

<ext:ComponentColumn
runat="server"
Editor="true"
DataIndex="DateField"
Flex="1"
Text="Date">
<Component>
<ext:DateField runat="server" />
</Component>
</ext:ComponentColumn>
</Columns>
</ColumnModel>
<Buttons><ext:Button
runat="server"
Text="Add Row"
Icon="Add"
OnDirectClick="btnAddService_Click"
/>
</Buttons>
</ext:GridPanel>
</form>
</body>
</html>

Daniil
Jan 17, 2013, 3:17 PM
Thank you for the sample.

Well, you rebind the old data with the myList.

The following is enough to add a new row.

Example

protected void btnAddService_Click(object sender, DirectEventArgs e)
{
this.Store1.Add(new List<object>() { new object[] { 11, 11, "Text 11", DateTime.Now.Date } });

// or
// this.Store1.Add(new { IntField = 11, ... });
}

marco.morreale
Jan 18, 2013, 5:35 AM
Thank you Daniil,
but this way myList is never modified so I can't process the rows later.

I also have a Save button (server side); on click I want to loop through myList items to process data in the gridpanel (save to db).

How can I achive this?

I tried "this.Store1.Data" or "this.Store1.record" but theese are null.

Thanks in advance.
Marco

Daniil
Jan 18, 2013, 6:36 AM
Well, you can add a record to the list after the Store's Add call.

But do you really need this list?

How will you manage editing? Are you going to monitor client side editing and update that list, on interim level between the client data and the database?

Personally, I would use the native grid/store data saving mechanism as demonstrated in our examples.
http://examples2.ext.net/#/search/saving
http://examples2.ext.net/#/GridPanel/Update/AutoSave/
http://examples2.ext.net/#/GridPanel/Update/Batch/
http://examples2.ext.net/#/GridPanel/Update/SqlDataSource/

marco.morreale
Jan 18, 2013, 8:55 AM
Thank you, Daniil

This fitted perfectly: http://examples2.ext.net/#/GridPanel/Update/Batch/

M