首页 > 程序开发 > web前端 > JavaScript >

gridpanel动态加载数据的例子

2011-08-19

<script type=&#39;text/javascript&#39;>function editEsOrder(options,success,response){if (success){var tagModelManager_maxOrderIdJson=Ext.util.JSON.decode(response.responseText);var orderValu...

<script type=&#39;text/javascript&#39;>

function editEsOrder(options,success,response){
if (success){
var tagModelManager_maxOrderIdJson=Ext.util.JSON.decode(response.responseText);
var orderValue = tagModelManager_maxOrderIdJson.maxOrderId ;
Ext.getCmp(&#39;esorder&#39;).setValue(orderValue) ;
}
}

var tagModelManager_toolBar=new Ext.Toolbar({
items:[
{id:&#39;tagModel_Save&#39;,text:&#39;添加&#39;,iconCls:&#39;add&#39;,handler:tagModel_Save}
,&#39;-&#39;,
{id:&#39;tagModel_dropSelected&#39;,text:&#39;删除&#39;,iconCls:&#39;remove&#39;,handler:tagModel_dropSelected}
]});

new Ext.grid.GridPanel({
id:&#39;tagModelManager_tagModelGrid&#39;,
autoScroll:true, store:new Ext.data.Store(),
cm:new Ext.grid.ColumnModel([new Ext.grid.RowNumberer()]),
sm:new Ext.grid.CheckboxSelectionModel(),
renderTo:&#39;tagModelManager_tagModelDiv&#39;,
width:Ext.getCmp(&#39;TagModel_win&#39;).getSize().width-16,
height:Ext.getCmp(&#39;TagModel_win&#39;).getSize().height-35,
hideHeaders :false,
loadMask:{msg:&#39;正在加载数据,请稍候....&#39;},
collapsible : true,
collapsed : false,
bbar:new Ext.PagingToolbar({
id:&#39;tagModelManager_tagModelPagingBar&#39;,
pageSize:getComboValue(),
store:new Ext.data.Store(),
displayInfo:true
}),
tbar:tagModelManager_toolBar
});
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).render() ;
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).on(&#39;rowdblclick&#39;, tagModelSelectRowDblClickEvent);
function tagModelSelectRowDblClickEvent(selectionModel, rowIndex, selectedRecord) {
var selectedRows = Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).getSelectionModel().getSelections();
var row=selectedRows[0];
tagModel_SaveOrEdit(&#39;edit&#39;,row);
}
function tagModel_Save() {
tagModel_SaveOrEdit(&#39;save&#39;);
}
function tagModelList_search() {
Ext.Ajax.request({
url:&#39;editTagModel.html?method=getParams&#39;,
callback:getSearchList
});
}
function getSearchList(options,success,response) {
if (success){
var tagModelManager_json=Ext.util.JSON.decode(response.responseText);
tagModelManager_tagModelGridTitle = tagModelManager_json.tagModelManager_tagModelGridTitle;
var record = tagModelManager_json.record ;
var tagModelManager_tagModelColumnModels = tagModelManager_json.tagModelManager_tagModelColumnModels ;
var tagModelManager_tagModelColumnModel=new Ext.grid.ColumnModel(Ext.util.JSON.decode("["+"new Ext.grid.RowNumberer()"+","+"new Ext.grid.CheckboxSelectionModel()"+","+tagModelManager_tagModelColumnModels+"]"));
tagModelManager_tagModelColumnModel.defaultSortable=true;
var strucutreModelManager_tagModelDataStore = new Ext.data.Store({
baseParams: { tagModelKeyword : Ext.getCmp(&#39;tagModelManager_search_button&#39;).el.dom.value.trim() },
proxy:new Ext.data.HttpProxy({
url:&#39;editTagModel.html?method=getTagModelDataList&#39;
}),
reader:new Ext.data.JsonReader({
totalProperty:&#39;resultSize&#39;,root:&#39;tagModelList&#39;},Ext.util.JSON.decode(record)) });
Ext.getCmp(&#39;tagModelManager_tagModelPagingBar&#39;).bind(strucutreModelManager_tagModelDataStore);
strucutreModelManager_tagModelDataStore.load({params:{start:0,limit:getComboValue()}}) ;
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).setTitle(tagModelManager_tagModelGridTitle) ;
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).reconfigure(strucutreModelManager_tagModelDataStore,tagModelManager_tagModelColumnModel);
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).expand(false) ;
}
}
function tagModelList_all(){
Ext.Ajax.request({
url:&#39;editTagModel.html?method=getParams&#39;,
callback:getTagModel
});
}
function getTagModel(options,success,response){
if (success){
var tagModelManager_json=Ext.util.JSON.decode(response.responseText);
tagModelManager_tagModelGridTitle = tagModelManager_json.tagModelManager_tagModelGridTitle;
var record = tagModelManager_json.record ;
var tagModelManager_tagModelColumnModels = tagModelManager_json.tagModelManager_tagModelColumnModels ;
var tagModelManager_tagModelColumnModel=new Ext.grid.ColumnModel(Ext.util.JSON.decode("["+"new Ext.grid.RowNumberer()"+","+"new Ext.grid.CheckboxSelectionModel()"+","+tagModelManager_tagModelColumnModels+"]"));
tagModelManager_tagModelColumnModel.defaultSortable=true;
var strucutreModelManager_tagModelDataStore = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({
url:&#39;editTagModel.html?method=getTagModelDataList&#39;
}),
reader:new Ext.data.JsonReader({
totalProperty:&#39;resultSize&#39;,root:&#39;tagModelList&#39;},Ext.util.JSON.decode(record)) });
Ext.getCmp(&#39;tagModelManager_tagModelPagingBar&#39;).bind(strucutreModelManager_tagModelDataStore);
strucutreModelManager_tagModelDataStore.load({params:{start:0,limit:getComboValue()}}) ;
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).reconfigure(strucutreModelManager_tagModelDataStore,tagModelManager_tagModelColumnModel);
Ext.getCmp(&#39;tagModelManager_tagModelGrid&#39;).expand(false) ;
}
}
Ext.Ajax.request({
url:&#39;editTagModel.html?method=getParams&#39;,
callback:getTagModel
});

</script>


public void getTagModelDataList(ActionMapping mapping, ActionForm actionform,HttpServletRequest request, HttpServletResponse response){
ITagModelManager tagmgr = this.getPkgServer().getDriver().getOperateServer().getTagModelManager() ;
List<HashMap<String,String>> models = new ArrayList<HashMap<String,String>>();
String tagModelKeyword = request.getParameter("tagModelKeyword");
List<EssTagModel> tagModels ;
tagModels = tagmgr.getEssTagModels() ;

int resultSize = 0 ;

if (null != tagModels && !tagModels.isEmpty()){
//数据分页显示
resultSize = tagModels.size() ;
String start = request.getParameter("start") ;
String perPage = request.getParameter("limit") ;
String esType ="";
if (null != start && null != perPage){
int fromIdx = Integer.parseInt(start);
int per = Integer.parseInt(perPage);
int toIdx = fromIdx + per ;
if (toIdx > resultSize) toIdx = resultSize ;
tagModels = tagModels.subList(fromIdx,toIdx) ;
}
for(EssTagModel etm : tagModels){
HashMap<String,String> map = new HashMap<String, String>();
map.put("id", Long.toString(etm.getId())) ;
map.put("esidentifier", etm.getEsidentifier()) ;

map.put("estype", etm.getEstype()) ;
map.put("esdescription", etm.getEsdescription()) ;
map.put("esorder", Long.toString(etm.getEsorder())) ;
map.put("metadata", etm.getMetadata()) ;
models.add(map) ;
}
}

JSONObject json = new JSONObject();
JSONArray ary = new JSONArray(models);
json.put("tagModelList", ary);
json.put("resultSize",resultSize);
writeJson(response, json.toString()) ;
}

public void getParams(ActionMapping mapping, ActionForm actionform,HttpServletRequest request, HttpServletResponse response){

LinkedHashMap<String,String> tags = new LinkedHashMap<String,String>() ;
tags.put("id", "id") ;
tags.put("esidentifier", "字段") ;
tags.put("estype", "类型") ;
tags.put("esdescription", "描述") ;
tags.put("esorder", "顺序") ;
tags.put("metadata", "元数据") ;
tags.put("esisnull", "是否为必填项") ;
tags.put("eslength", "字段长度") ;
tags.put("esdotlength", "小数点位数") ;
tags.put("esissystem", "是否为系统字段") ;

JSONObject json = new JSONObject();
json.put("record", getJsonRecord(tags)) ;
json.put("tagModelManager_tagModelColumnModels", getJsonColumnModel(tags)) ;
writeJson(response,json.toString());
}

相关文章
最新文章
热点推荐