电竞比分网-中国电竞赛事及体育赛事平台

分享

Ext中向Ext.grid.GridPanel() 顯示按鈕,并綁定id(行標(biāo)識(shí))

 windli筆記 2012-12-11

1、拼裝按鈕
備注:行標(biāo)識(shí)id,在加載顯示的時(shí)候就已和按鈕綁定到一起,并相應(yīng)的執(zhí)行按鈕操作;


  1. /*表格數(shù)據(jù)源*/  
  2. var store = new Ext.data.Store({  
  3.     proxy:new Ext.data.HttpProxy({url:'TestAction!testMethod.action'}),  
  4.     reader:new Ext.data.JsonReader({  
  5.         totalProperty:'total',  
  6.         root:'result'  
  7.     },  
  8.     [     
  9.         {name:'planedId'},                      /*安檢計(jì)劃唯一編號(hào)*/  
  10.         {name:'symbol'},                        /*編號(hào)*/  
  11.         {name:'smbDesc'},                       /*地址*/  
  12.         {name:'planedCnt'},                     /*戶(hù)數(shù)*/  
  13.         {name:'checkDatePlan'},                 /*計(jì)劃日期*/  
  14.         {name:'checkUnit'},                     /*安檢單位*/  
  15.         {name:'printTime'},                     /*打印時(shí)間*/  
  16.         {name:'cancel'}                         /*取消計(jì)劃*/  
  17.     ]),  
  18.     sortInfo:{field:'symbol',direction:'DESC'}  /*排序*/  
  19. });  
  20.   
  21. /*列模型中渲染的按鈕*/  
  22. var cancelRender = function cancel(value){  
  23.     cancelButton='<TABLE class="x-btn-wrap x-btn x-btn-text-icon" id=save style="WIDTH:55px" cellSpacing=0 cellPadding=0 border=0>';  
  24.     cancelButton+='<TBODY><TR><TD class=x-btn-left><I> </I></TD>';  
  25.     cancelButton+='<TD class=x-btn-center><EM unselectable="on"><BUTTON id=ext-gen97 onclick=cancel('+value+')>取消</BUTTON></EM></TD>';  
  26.     cancelButton+='<TD class=x-btn-right><I> </I></TD></TR></TBODY></TABLE>';  
  27.     return cancelButton;  
  28. };  
  29.   
  30. /*表格顯示項(xiàng) - 列模型*/  
  31. var cm = new Ext.grid.ColumnModel([  
  32.     {header:'編號(hào)',    width:200,dataIndex:'symbol'},  
  33.     {header:'地址',    width:200,dataIndex:'smbDesc'},  
  34.     {header:'戶(hù)數(shù)',    width:200,dataIndex:'planedCnt'},  
  35.     {header:'計(jì)劃日期',width:200,dataIndex:'checkDatePlan'},  
  36.     {header:'安檢單位',width:200,dataIndex:'checkUnit'},  
  37.     {header:'打印時(shí)間',width:150,dataIndex:'printTime'},  
  38.     {header:'取消計(jì)劃',width:150,dataIndex:'planedId',renderer:cancelRender}  
  39. ]);  
  40.   
  41. /*表格面板*/  
  42. var grid = new Ext.grid.GridPanel({  
  43.     store:store,  
  44.     cm:cm,  
  45.     loadMask: true,  
  46.     stripeRows:true,  
  47.     viewConfig:{forceFit:true}  
  48. });  
  49.   
  50. /*觸發(fā)按鈕事件*/  
  51. var cancel = function(value){  
  52.     Ext.Msg.confirm('提示','是否確定取消該計(jì)劃?',function(btn){  
  53.         if(btn!='yes'){  
  54.             return;  
  55.         }  
  56.         Ext.Ajax.request({  
  57.             url:'TestAction!testMethod.action',  
  58.             callback:function(o,s,r){  
  59.                 if(r.responseText=='success'){  
  60.                     Ext.Msg.alert('提示','取消成功!');  
  61.                     return;  
  62.                 }else{  
  63.                     Ext.Msg.alert('提示','r.responseText');  
  64.                     return;  
  65.                 }  
  66.             }  
  67.         });  
  68.     });  
  69. };    


2、返回圖片按鈕鏈接
備注:行標(biāo)識(shí)id,在圖片按鈕顯示過(guò)后,當(dāng)執(zhí)行按鈕事件時(shí),在函數(shù)中通過(guò)循環(huán)選擇模型來(lái)獲取,并相應(yīng)的執(zhí)行按鈕操作;
對(duì)于這個(gè)例子,我就不做太多贅述,簡(jiǎn)單最好。代碼中唯一改動(dòng)的就是,按鈕顯示的方式改變了。好了,我來(lái)寫(xiě)一下。
對(duì)于store的加載,省略。來(lái)說(shuō)列模型中按鈕的顯示

  1. Ext.namespace("MCGM");  /*MCGM為命名空間*/  
  2.   
  3. MCGM.cm = new Ext.grid.ColumnModel([  
  4.      new Ext.grid.RowNumberer(),  
  5.     {header:'客戶(hù)編號(hào)',width:150,dataIndex:'customerId'},   
  6.     {header:'客戶(hù)名稱(chēng)',width:150,dataIndex:'name'},  
  7.     {header:'地址',    width:150,dataIndex:'address'},  
  8.     {header:'組別',    width:150,dataIndex:'group0'},  
  9.     {header:'順序',    width:150,dataIndex:'order0'},  
  10.     {header:'調(diào)整',    width:150,,dataIndex:""menuDisabled:true,  
  11.     renderer:function(v){  
  12.             return "<a onclick='update()' style="cursor:pointer" mce_style="cursor:pointer"><img src="images/tz.jpg" mce_src="images/tz.jpg" /></a>";  
  13.         }  
  14.     }  
  15. ]);  
  16.   
  17. MCGM.grid = new Ext.grid.GridPanel({  
  18.     cm:MCGM.cm,  
  19.     store:MCGM.store,  
  20.     loadMask: {msg:'正在加載中,請(qǐng)稍后..'},                      //加載時(shí)顯示的等待信息  
  21.     sm:new Ext.grid.RowSelectionModel({singleSelect:true}),  
  22.        viewConfig:{forceFit:true,autoScroll:true},  
  23. });  
  24.   
  25. /*下面是我做的一個(gè)調(diào)整功能,需要跳到另外一個(gè)新頁(yè)面,并要獲得行的所有值,特別是行標(biāo)識(shí)id,這里我就只把獲得行信息的代碼寫(xiě)出來(lái),不怎么難,就幾行,還是寫(xiě)一下吧!*/  
  26. var update = function(){  
  27.     Ext.Msg.confirm("提示框","您確定要調(diào)整此項(xiàng)記錄嗎?",function(btn){  
  28.         if(btn == 'yes'){  
  29.             /*關(guān)鍵代碼*/  
  30.             MCGM.view = MCGM.grid.getView();  
  31.             MCGM.rsm = MCGM.grid.getSelectionModel();  
  32.             MCGM.store = MCGM.grid.getStore();  
  33.               
  34.             for(var i = MCGM.view.getRows().length-1;i>=0;i--){  
  35.                 if(MCGM.rsm.isSelected(i)){  
  36.                     var customerId = MCGM.grid.getStore().getAt(i).get('customerId');  
  37.                     var name = MCGM.grid.getStore().getAt(i).get('name');  
  38.                     var address = MCGM.grid.getStore().getAt(i).get('address');  
  39.                     var group0 = MCGM.grid.getStore().getAt(i).get('group0');  
  40.                     var order0 = MCGM.grid.getStore().getAt(i).get('order0');  
  41.                 }  
  42.             }  
  43.         }  
  44.     });  
  45. }; 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約