Aug 08, 2013, 11:43 PM
[CLOSED] Values in DataTable columns of type object are not rendered to json
Hi:
I discovered this because I need to read sql server sql_variant columns. The .net driver maps sql_variant columns to DataTable DataColumn objects of type object (typeof(object)).
The problem is that the values in these columns are not converted to json.
I attached a sample page where you can see what happens:
Thanks
Update: Sorry the original title of the thread doesn't make much sense. I changed it however, the forum app didn't seem to update the big title.
I discovered this because I need to read sql server sql_variant columns. The .net driver maps sql_variant columns to DataTable DataColumn objects of type object (typeof(object)).
The problem is that the values in these columns are not converted to json.
I attached a sample page where you can see what happens:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Import Namespace="Ext.Net.Calendar.Demo" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
DataTable dataTable = new DataTable("test");
dataTable.Columns.Add("Col1", typeof (int));
dataTable.Columns.Add("Col2", typeof(object));
dataTable.Rows.Add(1, "Row 1");
dataTable.Rows.Add(2, 2);
dataTable.Rows.Add(3, DateTime.Now);
Store1.DataSource = dataTable;
Store1.DataBind();
}
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>GridPanel with ObjectDataSource - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
<style>
.x-grid-cell-fullName .x-grid-cell-inner {
font-family : tahoma, verdana;
display : block;
font-weight : normal;
font-style : normal;
color : #385F95;
white-space : normal;
}
.x-grid-rowbody div {
margin : 2px 5px 20px 5px !important;
width : 99%;
color : Gray;
}
.x-grid-row-expanded td.x-grid-cell{
border-bottom-width:0px;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:GridPanel ID="GridPanel1"
runat="server"
Title="Employees"
Frame="true"
Height="600">
<Store>
<ext:Store ID="Store1" runat="server" >
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="EmployeeID">
<Fields>
<ext:ModelField Name="Col1" Type="Int"/>
<ext:ModelField Name="Col2" Type="Auto"/>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" DataIndex="Col1" Text="Col1" Width="150" />
<ext:Column ID="Column2" runat="server" DataIndex="Col2" Text="Col2" Width="150" />
</Columns>
</ColumnModel>
<View>
<ext:GridView ID="GridView1" runat="server">
<GetRowClass Handler="return 'x-grid-row-expanded';" />
</ext:GridView>
</View>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single" />
</SelectionModel>
</ext:GridPanel>
</form>
</body>
</html>
The generated JavaScript code contains the data for the store coming from the DataTable object. Note that Col2 is missing from the data json object.Ext.net.ResourceMgr.init({
id: "ResourceManager1",
aspForm: "Form1",
theme: "gray"
});
Ext.onReady(function () {
Ext.create("Ext.grid.Panel", {
store: {
model: Ext.define("App.Model1", {
extend: "Ext.data.Model",
fields: [{
name: "Col1",
type: "int"
}, {
name: "Col2"
}],
idProperty: "EmployeeID"
}),
storeId: "Store1",
autoLoad: true,
proxy: {
data: [{
"Col1": 1
}, {
"Col1": 2
}, {
"Col1": 3
}],
type: 'memory'
}
},
id: "GridPanel1",
frame: true,
height: 600,
renderTo: "App.GridPanel1_Container",
title: "Employees",
columns: {
id: "ColumnModel1",
items: [{
id: "Column1",
width: 150,
dataIndex: "Col1",
text: "Col1"
}, {
id: "Column2",
width: 150,
dataIndex: "Col2",
text: "Col2"
}]
},
selModel: window.App.RowSelectionModel1 = Ext.create("Ext.selection.RowModel", {
proxyId: "RowSelectionModel1",
selType: "rowmodel"
}),
viewConfig: {
id: "GridView1",
xtype: "gridview",
getRowClass: function (record, index, rowParams, store) {
return 'x-grid-row-expanded';
}
}
});
});
Any workaround to get all the data from the DataTable object ?Thanks
Update: Sorry the original title of the thread doesn't make much sense. I changed it however, the forum app didn't seem to update the big title.
Last edited by Baidaly; Aug 10, 2013 at 1:38 AM.
Reason: [CLOSED]