生活随笔
收集整理的這篇文章主要介紹了
Ext.grid.EditorGridPanel使用方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先定義一個EditorGridPanel,
[c-sharp]?view plaincopyprint?
var?maintainceOrderGrid?=?new?Ext.grid.EditorGridPanel(?{??????????????????????????applyTo?:?'maintainorderinfo-grid-div',??????????????????????????frame?:?true,??????????????????????????tbar?:?toolbar,??????????????????????????stripeRows?:?true,??????????????????????????autoScroll?:?true,??????????????????????????store?:?maintainceProjectStore,??????????????????????????viewConfig?:?{??????????????????????????????autoFill?:?true??????????????????????????},??????????????????????????sm?:?sm,??????????????????????????cm?:?cm,??????????????????????????bbar?:?new?Ext.PagingToolbar(?{??????????????????????????????pageSize?:?25,??????????????????????????????store?:?maintainceProjectStore,??????????????????????????????displayInfo?:?true,??????????????????????????????displayMsg?:?'顯示第{0}條到{1}條記錄,一共{2}條記錄',??????????????????????????????emptyMsg?:?'沒有記錄'??????????????????????????})??????????????????????});?? ?
?
接著定義grid中用到的sm和cm,
[c-sharp]?view plaincopyprint?
var?sm?=?new?Ext.grid.CheckboxSelectionModel();??????????var?cm?=?new?Ext.grid.ColumnModel(?[??????????????????new?Ext.grid.RowNumberer(),?sm,?{??????????????????????header?:?"維修價格",??????????????????????width?:?60,??????????????????????dataIndex?:?'price',??????????????????????sortable?:?true,??????????????????????editor?:?new?Ext.form.NumberField(?{??????????????????????????editable?:?true,??????????????????????????allowNegative?:?false,??????????????????????????allowBlank?:?false,??????????????????????????decimalPrecision?:?2,??????????????????????????minValue?:?0??????????????????????????????????????????????????????????????????????????????????})??????????????????}?]);?? ?
?
再定義一個保存維修價格的toolbar,用于調用保存維修價格的方法。
[c-sharp]?view plaincopyprint?
var?toolbar?=?new?Ext.Toolbar(?[??{??????????????????text?:?'保存維修價格',??????????????????iconCls?:?'add',??????????????????handler?:?setMaintaincePrice??????????????}?]);?? ?
?
保存維修價格的方法如下:
[c-sharp]?view plaincopyprint?
function?setMaintaincePrice()?{??var?mr?=?maintainceProjectStore.getModifiedRecords();??var?recordCount?=?maintainceProjectStore.getCount();????if?(mr.length?==?0)?{??????Ext.MessageBox.alert('提示',?'沒有修改數據!');??}???else???{??????var?msgTip?=?Ext.MessageBox.show(?{??????title?:?'提示',??????width?:?250,??????msg?:?'正在提交更改請稍后......'??});??var?recordModStr?=?"[";??for?(?var?i?=?0;?i?<?mr.length;?i++)?{??????recordModStr?+=?"{maintainceProjectId:"??????????????+?mr[i].data["maintainceProjectId"]?+?",price:"??????????????+?mr[i].data["price"]?+?"}";??????if?(i?<?mr.length?-?1)??????????recordModStr?+=?",";??}??recordModStr?+=?"]";??var?requestConfig?=?{????????????url?:?'maintianceproject.do?method=setMaintaincePrice×tamp='?+?new?Date(),??????jsonData?:?recordModStr,??????params?:?{??????????mlist?:?recordModStr??????},??????callback?:?function(options,?success,?reponse)?{??????????msgTip.hide();??????????if?(success)?{??????????????Ext.Msg.alert('提示',?'保存成功');??????????????maintainceProjectStore.commitChanges();??????????}?else?{??????????????Ext.Msg.alert('提示',?'保存失敗');??????????}??????}??}??Ext.Ajax.request(requestConfig);????????}?? ?
這里使用了
[c-sharp]?view plaincopyprint?
Ext.Ajax.request(requestConfig);?? ?
Ajax動態向后臺發送請求的方法。這也是ExtJs前后臺傳遞消息的有效方法之一。
?
下面列出后臺讀取josn的方法:
[c-sharp]?view plaincopyprint?
private?ModelAndView?setMaintaincePrice(HttpServletRequest?request,??????????????HttpServletResponse?response)?throws?IOException?{??????????String?jsonstr?=?request.getParameter("mlist");????????????????????System.out.println(jsonstr);??????????jsonstr?=?URLDecoder.decode(jsonstr,?"utf-8");??????????JSONArray?array?=?JSONArray.fromObject(jsonstr);??????????MaintianceprojectForm[]?obj?=?new?MaintianceprojectForm[array.size()];??????????boolean?b?=?false;??????????for?(int?i?=?0;?i?<?array.size();?i++)?{??????????????JSONObject?jsonObject?=?array.getJSONObject(i);??????????????obj[i]?=?(MaintianceprojectForm)?JSONObject.toBean(jsonObject,??????????????????????MaintianceprojectForm.class);????????????????????????????System.out.println(obj[i].getMaintainceProjectId()?+?"*****"??????????????????????+?obj[i].getPrice());??????????????Maintianceproject?record?=?new?Maintianceproject();??????????????record.setPrice(obj[i].getPrice());??????????????b?=?this.getMaintianceprojectService().updateMaintaincePrice(??????????????????????obj[i].getMaintainceProjectId(),?record);??????????????if?(b?==?false)??????????????????break;??????????}??????????if?(b)?{??????????????response.getWriter().write("{success:true}");??????????}?else?{??????????????response.getWriter().write("{success:false}");??????????}??????????return?null;??????}?? ?
?
本文轉自xwdreamer博客園博客,原文鏈接:http://www.cnblogs.com/xwdreamer/archive/2010/12/29/2297054.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的Ext.grid.EditorGridPanel使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。