PDA

View Full Version : [CLOSED] Store issue in new version



shaileshsakaria
Jul 08, 2014, 12:04 PM
Hi,

Recently I converted to new ext.net version from 2.1 to 2.5. but I got one issue while using getChangedData() method on store.

Here I have attached minified sample.

First click on "Add In Grid" button to add new record and then click on "Save" button, on save button code, I am not getting added records count, can you suggest me what is wrong with this?




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

<ext:ResourceManager ID="Res1" runat="server"></ext:ResourceManager>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!X.IsAjaxRequest)
{
List<BloodGroup> lstBloodGroup = new List<BloodGroup>();
this.StoreBloodGroup.DataSource = lstBloodGroup.ToList();
this.StoreBloodGroup.DataBind();
}
}
catch (Exception ex)
{
throw (ex);
}
}

protected void Save_Click(object sender, DirectEventArgs e)
{
try
{
ChangeRecords<BloodGroup> bloodgroups = new StoreDataHandler(e.ExtraParams["BloodGroupData"]).BatchObjectData<BloodGroup>();

if (bloodgroups.Deleted.Count > 0 || bloodgroups.Created.Count > 0 || bloodgroups.Updated.Count > 0)
{
string message = "";
message = "Inserted Records : " + bloodgroups.Created.Count.ToString();
message += "Updated Records : " + bloodgroups.Updated.Count.ToString();
message += "Deleted Records : " + bloodgroups.Deleted.Count.ToString();
new MessageBox().Show(new MessageBoxConfig()
{
Title = " ",
Message = message,
Buttons = MessageBox.Button.OK,
});
}
else
{
new MessageBox().Show(new MessageBoxConfig()
{
Title = " ",
Message = "No Records to be saved!",
Buttons = MessageBox.Button.OK,
});
}
}
catch (Exception ex)
{
throw (ex);
}
}

protected void btnAddInGrid_Click(object sender, DirectEventArgs e)
{
try
{
BloodGroup bg = new BloodGroup();
bg.BloodGrpName = "abc";
this.StoreBloodGroup.Add(bg);
}
catch (Exception ex)
{
throw (ex);
}
}

public class BloodGroup
{
public long BloodGrpID { get; set; }
public string BloodGrpName { get; set; }
}
</script>
<ext:GridPanel runat="server" ID="GridBloodGroup"
IDMode="Static" ColumnLines="true" Height="600">
<Store>
<ext:Store runat="server" ID="StoreBloodGroup" IDMode="Static">
<Model>
<ext:Model runat="server" ID="ModelBloodGroup" IDProperty="BloodGrpID">
<Fields>
<ext:ModelField Name="BloodGrpID" Type="Int" />
<ext:ModelField Name="BloodGrpName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="Column1" runat="server" DataIndex="BloodGrpID" Text="Blood Group ID" Sortable="true" Width="110">
<Editor>
<ext:TextField ID="TextField1" runat="server" AllowBlank="false">
</ext:TextField>
</Editor>
</ext:Column>
<ext:Column ID="colBloodGroupName" runat="server" DataIndex="BloodGrpName" Text="Blood Group Name" Sortable="true" Hideable="true" Width="110">
<Editor>
<ext:TextField ID="txtBloodGroupName" runat="server" AllowBlank="false">
</ext:TextField>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing ID="CellEditing1" runat="server" ClicksToEdit="1">
</ext:CellEditing>
</Plugins>
<Buttons>
<ext:Button ID="btnAddInGrid" runat="server" IDMode="Static" Icon="Add" Text="Add In Grid">
<DirectEvents>
<Click OnEvent="btnAddInGrid_Click" />
</DirectEvents>
</ext:Button>

<ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
<DirectEvents>
<Click OnEvent="Save_Click">
<ExtraParams>
<ext:Parameter Name="BloodGroupData" Value="App.StoreBloodGroup.getChangedData({skipIdForNewRe cords : true})" Mode="Raw" Encode="true" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:GridPanel>

Daniil
Jul 08, 2014, 12:53 PM
Hi @shaileshsakaria,

This

BloodGroup bg = new BloodGroup();
creates an instance of the BloodGroup type where BloodGrpID is 0 by default.

That zero goes to a client side:

{script:"App.StoreBloodGroup.add({\"BloodGrpID\":0,\"BloodGrpName\":\"abc\"});"}

It means that you have explicitly set up the IDProperty ModelField. Such a record is not considered as a new one. It is considered as already saved. Therefore it doesn't go to .getChangedData().

Your scenario might work with a Nullable long.

public long? BloodGrpID { get; set; }

shaileshsakaria
Jul 08, 2014, 1:38 PM
Thanks for your reply.

By doing Nullable long its working but I can't do nullable to primary key as I have binded Entity framework classes directly to Store in almost all pages (more than 300 pages). In old version (2.1) the same thing was working, can you tell me easy solution?


Thanks

Daniil
Jul 08, 2014, 5:10 PM
In old version (2.1) the same thing was working

I would say it was a bug.


can you tell me easy solution?

Is that acceptable?

this.StoreBloodGroup.Add(new
{
BloodGrpName = "abc"
});

Also you might need to use a UseNull option.

<ext:ModelField Name="BloodGrpID" Type="Int" UseNull="true" />

shaileshsakaria
Jul 12, 2014, 7:12 AM
Thanks for reply.

Yes its worked.