extjs - Ext js grouping grid cant load json data -
i cant able load data in ext js grouping grid.
i have following code 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 file 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 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 server'); }, failure : function(fp, o){ msg('failure', 'failed upload'); } }); } } } }] }); });
and have following json string in 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" }] } ] }
still cant able load data ,
plz me , sort out problem, had done mistake.
well problem store reader, has set root "documents" json recieved has root "documentlist". problem mapping json data store.
edit problem using incorectly grouping store. data not need grouped when getting backend. here suggestion : json sent backend list of documents in have type
{ "documents": [{ "type":"invoice","filename": "abc.doc", "size": "123", "author": "xyz", "date": "\/date(1238025600000)\/", "filegpath": "xyz doc", "document" : "invoice" }, {"type":"invoice", "filename": "abc.doc", "size": "123", "author": "xyz", "date": "\/date(1238025600000)\/", "filegpath": "abc doc", "document" : "invoice" }, {"type":"sop", "filename": "abc.doc", "size": "123", "author": "xyz", "date": "\/date(1238025600000)\/", "filegpath": "xyz doc", "document" : "sop" }] } and grouping store use groupfield: "type" , , reader should have root "documents". simplify load means have duplicate data need each group , attach each document. suggestion.
Comments
Post a Comment