Customize one of the JS
function Commodityquery () {
Ext.state.Manager.setProvider (ext.create (' Ext.state.CookieProvider '));
Set up a model to use in our Store
Ext.define (' commodity ', {
Extend: ' Ext.data.Model ',
Fields: [
{name: ' Commodityid ', type: ' int '},
{name: ' Commodityname ', type: ' String '},
{name: ' Price ', type: ' Float '},
{name: ' Agio ', type: ' Float '}
]
});
var store = ext.create (' Ext.data.Store ', {
Model: ' Commodity ',
Proxy: {
Type: ' Ajax ',
URL: ' Commodityquery ',
Successproperty: ' Success ',
Reader: {
Type: ' JSON ',
Root: ' Results '
}
},
AutoLoad: {Start:0,limit:4}
});
var gridpanel = ext.create (' Ext.grid.Panel ', {
width:586,
height:375,
Store:store,
Columns: [{
Text: "Product number",
Dataindex: "Commodityid",
Sortable:true
}, {
Text: "Product name",
Dataindex: "Commodityname",
Sortable:true
}, {
Text: "Commodity price",
Dataindex: "Price",
Sortable:true,
Autowidth:50
}, {
Text: "Merchandise Discount",
Dataindex: "Agio",
Sortable:true
} ],
Forcefit:true,
Bbar: [Ext.create ("Ext.toolbar.Paging", {
Store:store,
Displayinfo:true,
Displaymsg: "Show {0}-{1} bar, total {2}",
Emptymsg: "No Records",
Width: "100%"
}) ]
});
var Commodityquerywindow = ext.create ("Ext.window.Window", {
width:600,
height:400,
Title: "Product Information Inquiry",
Resizable:false,
Modal:true,
Items:gridpanel
});
Commodityquerywindow.show ();
}
**********************
Configuration in the Struts.xml
Method can be written in DMI mode
<action name= "Commodityquery" class= "com.rjxy.action.CommodityQueryAction" method= "getcommodity" >
<result type= "JSON" >
<param name= "Root" >responseJson</param>
</result>
</action>
**********************
The variables and methods in Commodityqueryaction
Private String msg;
Private list<commodity> List;
Private Integer TotalCount;
Private Map Responsejson;
Private Saledaoimpl DAO;
Private Integer start;
Private Integer limit;
/**
* Query commodity list.
*/
Public String getcommodity () {
map<string, object> map = new hashmap<string, object> ();
try{
conn = Getconnection.getconn ();//jdbc connection, users can use Hibernate
DAO = new Saledaoimpl ();
List = Dao.queryallorder ();
if (list! = null) {
This.settotalcount (List.size ());
Map.put ("Results", list);
Map.put ("TotalCount", totalcount);
This.setresponsejson (map);
}
return SUCCESS;
}catch (Exception e) {
E.printstacktrace ();
return ERROR;
}
This article is from the "Learning" blog, so be sure to keep this source http://kefly.blog.51cto.com/1109349/1584415
ExtJS 4.2 +struts2 for Dynamic Data loading