求一EXTJS 的grid控件绑定后台dt简单例子

长江 2011-11-16 12:24:33
自己摸了两天还是没搞出来。
求一例子:
用VS2010的MVC建的项目,EXTJS 4.0 中的GRID控件从后台DataTable中取数据

例子最好简单点两三个字段就行了!谢谢!
...全文
324 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
IT民工010 2013-06-20
  • 打赏
  • 举报
回复
drfv
[align=center]wer[align=right]wer
[/align][/align]
长江 2011-11-17
  • 打赏
  • 举报
回复
jshi123 2011-11-17
  • 打赏
  • 举报
回复

public void ProcessRequest(HttpContext context)
{
string str = "{\"totalCount\":\"1\",\"topics\":[{\"title\":\"XTemplate with in EditorGridPanel\",\"threadid\":\"133690\",\"username\":\"kpr@emco\",\"userid\":\"272497\",\"dateline\":\"1305604761\",\"postid\":\"602876\",\"forumtitle\":\"Ext 3.x: Help\",\"forumid\":\"40\",\"replycount\":\"2\",\"lastpost\":\"1305857807\",\"excerpt\":\"\"}]}";
str = context.Request["callback"] + "(" + str + ")";
context.Response.Write(str);
}
阿非 2011-11-16
  • 打赏
  • 举报
回复
mvc 还是 webform
长江 2011-11-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hefeng_aspnet 的回复:]
参考:http://blog.csdn.net/linkyou/article/details/6586387
[/Quote]

没看到有后台传数据
长江 2011-11-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 vanceinfo_zhao 的回复:]
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{ header: '单位代码', dataIndex: 'UnitId', sortable: true, hidden: true },
{ header: '单位代码', dataIndex: 'TypeCode', sortable: true,……
[/Quote]

运行到第一句就报错“缺少对象”~!
长江 2011-11-16
  • 打赏
  • 举报
回复
这是原来带有的例子,数据源是url: 'http://www.sencha.com/forum/remote_topics/index.php',
可以正常显示数据,

var store = Ext.create('Ext.data.Store', {
id: 'store',
pageSize: 200,
model: 'ForumThread',
remoteSort: true,
// allow the grid to interact with the paging scroller by buffering
buffered: true,
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better

type: 'jsonp',
url: 'http://www.sencha.com/forum/remote_topics/index.php',
extraParams: {
total: 50000
},
reader: {
root: 'topics',
totalProperty: 'totalCount'
},
// sends single sort as multi parameter
simpleSortMode: true
},
sorters: [{
property: 'lastpost',
direction: 'DESC'
}]
});

但是我改成我的'Handler2.ashx'之后怎么搞都没数据出来

url: 'Handler2.ashx',


Handler2.ashx里换了N种写法JS都没收到数据

public void ProcessRequest(HttpContext context)
{
string str = "{\"totalCount\":\"1\",\"topics\":[{\"title\":\"XTemplate with in EditorGridPanel\",\"threadid\":\"133690\",\"username\":\"kpr@emco\",\"userid\":\"272497\",\"dateline\":\"1305604761\",\"postid\":\"602876\",\"forumtitle\":\"Ext 3.x: Help\",\"forumid\":\"40\",\"replycount\":\"2\",\"lastpost\":\"1305857807\",\"excerpt\":\"\"}]}";
context.Response.Write(str);
}


郁闷啊!!!
paul_its 2011-11-16
  • 打赏
  • 举报
回复
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{ header: '单位代码', dataIndex: 'UnitId', sortable: true, hidden: true },
{ header: '单位代码', dataIndex: 'TypeCode', sortable: true, width: 100 },
{ header: '单位名称', dataIndex: 'UnitNAME', sortable: true, width: 110 }
]);
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url: 'UnitList.aspx?cmd=list' }),//你请求数据的路径
reader: new Ext.data.JsonReader({ totalProperty: 'totalProperty', root: 'root' },
[
{ name: 'UnitId' },
{ name: 'TypeCode' },
{ name: 'UnitNAME' }
]
),
});

var grid = new Ext.grid.GridPanel({
store: store,
cm: cm,
renderTo: Ext.getBody(),
border: false,
stripeRows: true,
loadMask: true,
frame: false,
autoHeight: true,
viewConfig: { forceFit: true },
monitorResize: true,
listeners:
{
"rowdblclick": function (grid, rowIndex, e) {
alert("行双击事件!"); }
}
});
store.load();
------------------华丽的分割线--------------------
if (Request.QueryString["cmd"].Equals("list"))
{
#region 获取数据
IList<FDNE_UNIT_Entity> list =new Unit_BLL().GetUnitList();//获取数据返回泛型集合
StringBuilder str = new StringBuilder();
str.Append("{totalProperty:" + list.Count + ",root:[");
if (list == null || list.Count == 0)
{
str.Append("]}");
Response.Write(str.ToString());
return;
}
for (int i = 0; i < list.Count; i++)
{
str.Append("{TypeCode:'" + list[i].Unitcode + "',UnitNAME:'" + list[i].Unitname + "',UnitId:'" + list[i].Unitid + "'}");
if (i < (list.Count) - 1)
str.Append(",");
}
str.Append("]}");
Response.Write(str.ToString());
Response.End();
#endregion
}

你要的是从后台DataTable中取数据,我这是从集合中取都只需循环即可。希望你懂得......
csdn_aspnet 2011-11-16
  • 打赏
  • 举报
回复

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧