我无法在 ExtJS 分组中加载数据grid
。
我有以下代码 ExtJS grouping.js
。
Ext.onReady(function() {
Ext.QuickTips.init();
var xg = Ext.grid;
var documentType = "";
var fileName = "";
var size = "";
var fileGPath = "";
// shared reader
var reader = new Ext.data.ArrayReader({}, [{
name: 'filename'
}, {
name: 'size'
}, {
name: 'author'
}, {
name: 'date',
type: 'date',
dateFormat: 'Y-m-d H:i:s'
}, {
name: 'action'
}, {
name: 'document'
}
]);
var store = new Ext.data.GroupingStore({
reader: reader,
url: 'DocumentListService.jsp',
root: 'Documents',
sortInfo: {
field: 'filename',
direction: "ASC"
},
fields: [{
name: 'filename',
mapping: 'FileName'
}, {
name: 'size',
mapping: 'Size'
}, {
name: 'author',
mapping: 'Author'
}, {
name: 'date',
mapping: 'Date'
}, {
name: 'action',
mapping: ''
}, {
name: 'document',
mapping: 'Document'
}],
groupField: 'document'
});
var grid = new xg.GridPanel({
id: 'myGridId',
store: store,
columns: [{
id: 'filename',
header: "File Name",
width: 60,
sortable: true,
dataIndex: 'filename'
}, {
header: "Size",
width: 20,
sortable: true,
dataIndex: 'size'
}, {
header: "Author",
width: 20,
sortable: true,
dataIndex: 'author'
}, {
header: "Date",
width: 20,
sortable: true,
dataIndex: 'date'
}, {
header: "Action",
width: 20,
sortable: true,
dataIndex: 'action'
}, {
header: "Document",
width: 20,
sortable: true,
dataIndex: 'document',
hidden: 'true'
}],
view: new Ext.grid.GroupingView({
forceFit: true,
groupTextTpl: '{text} ({[values.rs[0].get("filename")=="" ? "0" : values.rs.length]} {[values.rs.length > 1 ? "Documents" : "Document"]}) <a href="#" onClick="javascript:document.getElementById(\'hdnId\').value=\'{text}\';document.getElementById(\'form-file-file\').click();" style="align:right"><img src="images/image_add.png" alt="Upload Document" style="border:none;margin-left:390px;"/></a>'
}),
frame: true,
width: 700,
height: 450,
collapsible: true,
animCollapse: false,
title: 'Document Library',
iconCls: 'icon-grid',
renderTo: 'docUpload'
});
var fp = new Ext.FormPanel({
renderTo: 'fi-form',
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select a File to import',
fieldLabel: 'File',
name: 'file',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
},
listeners: {
'fileselected': function(v) {
if (fp.getForm().isValid()) {
fp.getForm().submit({
url: 'FileUpload.jsp',
waitMsg: 'Uploading your file...',
success: function(fp, jsonObj) {
fileName = jsonObj.result.fileName;
size = jsonObj.result.size;
fileGPath = jsonObj.result.fileGPath;
documentType = (document.getElementById("hdnId").value).replace("Document: ", "");
addDataToGrid(fileName, fileGPath, size, documentType);
Ext.getCmp('myGridId').getStore().loadData(xg.dummyData);
msg('Success', 'Successfully uploded on the server');
},
failure: function(fp, o) {
msg('Failure', 'Failed to upload');
}
});
}
}
}
}]
});
});
我有以下json
字符串DocumentListService.jsp
:
{
"DocumentList": [{
"DocumentGroup": "Invoice",
"isDocumentBundle": true,
"isWritable": true,
"Documents": [{
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\\/Date(1238025600000)\\/",
"FileGPath": "xyz doc",
"Document": "Invoice"
}, {
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\\/Date(1238025600000)\\/",
"FileGPath": "abc doc",
"Document": "Invoice"
}]
}, {
"DocumentGroup": "SOP",
"isDocumentBundle": true,
"isWritable": true,
"Documents": [{
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\\/Date(1238025600000)\\/",
"FileGPath": "xyz doc",
"Document": "SOP"
}]
}]
}
我仍然无法加载数据。