PDA

View Full Version : [CLOSED] dateColumn value does not display when it is null



CPA1158139
Jul 12, 2014, 3:15 PM
Pls see my code.
I want the str1 result is : 3m Co,2014-07-12T00:00:00;4m Co,''
But it report error when clicked button.


thanks a lot.



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

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Xml" %>

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

<!DOCTYPE html>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Store1.DataSource = new object[]
{
new object[] { "3m Co", "2014-07-12"},
new object[] { "4m Co", ""}
};

this.Store1.DataBind();
}
}

protected void SubmitGrids(object sender, DirectEventArgs e)
{
//JSON representation
string grid1Json = e.ExtraParams["Grid1"];
string str1 = string.Empty;
//XML representation
XmlNode grid1Xml = JSON.DeserializeXmlNode("{records:{record:" + grid1Json + "}}");
//array of Dictionaries
Dictionary<string, string>[] grid1Data = JSON.Deserialize<Dictionary<string, string>[]>(grid1Json);
foreach (var record in grid1Data)
{
str1 += record["company"].ToString()+",";
str1 += record["date1"].ToString() + ";";
}

X.Msg.Alert("Submit", "why is dateColumn does not display when it is null?").Show();
}
</script>

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

<h1>Submit two grids in one request</h1>

<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="company" />
<ext:ModelField Name="date1" Type="Date" />

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



<ext:GridPanel
ID="GridPanel1"
runat="server"
StoreID="Store1"
Title="Grid"
Width="600"
Height="150">
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Company" Width="160" DataIndex="company" Flex="1" />
<ext:DateColumn runat="server" Text="date1" Width="115" DataIndex="date1" Format="yyyy-MM-dd" />

</Columns>
</ColumnModel>
</ext:GridPanel>



<ext:Button ID="Button1" runat="server" Text="get gridValue">
<DirectEvents>
<Click OnEvent="SubmitGrids">
<ExtraParams>
<ext:Parameter Name="Grid1" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOn ly : false}))" Mode="Raw" />

</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>

Daniil
Jul 14, 2014, 12:53 PM
Hi @CPA1158139,

If no value, it is not submitted to the server.

So, the second record doesn't have this dictionary item:

record["date1"]

Therefore it throws an Exception.

I can suggest

<ext:ModelField Name="date1" Type="Date" SubmitEmptyValue="Null" />
and

str1 += record["date1"] != null ? record["date1"].ToString() + ";" : "null";

CPA1158139
Jul 15, 2014, 12:19 AM
It's OK.
Thanks very much!