求教Extjs 4 关于Ext.grid.Panel数据显示问题

talantlee 2014-04-23 05:46:38
    var Cols = [{ 'header': 'Item No', 'dataIndex': 'itemno', 'width': 80, sortable: false },
{ 'header': 'Qty', 'dataIndex': 'qty', 'width': 80 },
{ 'header': 'Length', 'dataIndex': 'leng', 'width': 80 },
{ dataIndex: 'pgmname', header: 'Material', width: 110, align: 'center' },
{ 'header': 'Color', 'dataIndex': 'colorname', 'width': 150 },
{ 'header': 'Specification', 'dataIndex': 'specdesc', 'width': 280 }
];
var queryParams = { configtype: "getlist"} ;
var DS = Ext.create('Ext.data.JsonStore', {
proxy: {
type: 'ajax',
actionMethods: { read: "POST" },
extraParams: queryParams,
url: 'OrderPartOps.ashx'
},
reader: {
type: 'json',
root: 'rows',
totalProperty: 'total'
},
fields: [
{ name: 'itemno', type: 'int' },
{ name: 'qty' },
{ name: 'leng', type: 'int' },
{ name: 'uprice', type: 'float' },
{ name: 'pgmname' },
{ name: 'colorname' },
{ name: 'userid' },
{ name: 'sessionid' },
{ name: 'orderno' },
{ name: 'needreview' },
{ name: 'specdesc' }
],
listeners: { load: function(store, records, success, opts) {
alert(store.data.getCount());//这里结果为“1”
},
autoLoad: true
}
});

Ext.create("Ext.grid.Panel", {
id: 'configGrid1',
title: 'Shutters',
store: DS,
columns: Cols,
displayInfo: true,
emptyMsg: "no data",
sortableColumns: false,
renderTo: 'dtdetail'
});
DS.load();

代码如上,我的Grid 会显示一笔记录,但里面每个字段的值都是空的
请问上面的代码那里出错?
注:服务端返回的资料如下
{
"total": 1,
"rows": [
{
"userid": "MIS",
"sessionid": "49",
"itemno": "1",
"matchitemno": "0",
"pgmcode": "WTK",
"colorid": "049",
"customcolor": "Stone Grey",
"leng": "100.00",
"qty": "1",
"kindid": "BG",
"specid": "BG03",
"specdesc": "Bypass Bottom Guide E (W)",
"adduser": "Mis",
"remark": "",
"adddate": "2013/9/4 23:39:50",
"updtdate": "2013/9/4 23:39:50",
"updtuser": "Mis",
"orderno": "",
"needreview": "False",
"waive": "N",
"uprice": "0.00",
"pgmname": "White Teak",
"colorname": "049 Stone Grey"
}
]
}
请在现有代码基础上修改,谢谢!

付:下面这种方法我是暂时用的
Ext.Ajax.request({
success: function() {
var jsonResult = Ext.JSON.decode(arguments[0].responseText);
var ds = Ext.create('Ext.data.Store', {
fields: [
{ name: 'itemno', type: 'int' },
{ name: 'qty' },
{ name: 'leng', type: 'int' },
{ name: 'uprice', type: 'float' },
{ name: 'pgmname' },
{ name: 'colorname' },
{ name: 'userid' },
{ name: 'sessionid' },
{ name: 'orderno' },
{ name: 'needreview' },
{name: 'specdesc' }
],
data: jsonResult.rows
});
Ext.create("Ext.grid.Panel", {
id: 'configGrid',
name: 'configGrid',
title:'Parts',
store: ds,
columns: Cols,
displayInfo: true,
emptyMsg: "no data",
sortableColumns: false,
renderTo:'dtdetail'
});
}




...全文
183 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
talantlee 2014-04-24
  • 打赏
  • 举报
回复
我知道第2种方法是没什么不好,只是想知道第1种写法那里有问题。 我把创建Panel的代码直接放在listeners :load 里面也不行。 其实之前我有说明: 在garid里面 是有显示一行资料的,但里面值全是默认值。 个人感觉是数据已经读回来了,但可能程序没识别为json格式,因为用ajax的方法需要用Json.decode解析数据, 所以是不是那里我有个参数没设定好呢? 求解
talantlee 2014-04-24
  • 打赏
  • 举报
回复
查了一天的源吗,发现是个坑造成的。 reader属性要放到proxy中,才对
googny 2014-04-23
  • 打赏
  • 举报
回复
第一段代码 可以把DS打印出来看看是不是成功了。 如果成功了,看看是不是需要的那段 rows:[ xxx], 下面的配置grid panel没什么好说的,你都直接把DS配上去了,格式肯定得是[ key:value,xxx...]这样的。 --------------- DS.load() 我明白你的意思, 但是load之后意思应该是从后台得到数据吧,然后你还得对你的grid进行reload() 操作吧。 不然怎么可能会直接反应在页面上呢。 pps 我没看出第二种没什么不好的。 我的项目中就是这么配的。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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