免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
dojox.grid.DataGrid編程篇(1) -- Layout設(shè)計(jì)
最近使用了dojo組件,其中使用了 dojox.grid.DataGrid 進(jìn)行一覽表示的核心組件,這里總結(jié)一些實(shí)際使用中遇到的問題和解決方法。
官方Guide: http://dojotoolkit.org/reference-guide/1.8/dojox/grid/DataGrid.html

【準(zhǔn)備】
引用 DataGrid 的 CSS,dojo js,導(dǎo)入要使用的組件:

  1. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojo/resources/dojo.css">  
  2. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojox/grid/resources/claroGrid.css">  
  3. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.0/dijit/themes/claro/claro.css">  
  4.       
  5. <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojo/dojo.js" djConfig="parseOnLoad:true,locale:'ja-jp',isDebug:true"></script>  
  6. <script type="text/javascript">  
  7.       
  8. dojo.require("dojo.data.ItemFileWriteStore");  
  9. dojo.require("dojox.grid.DataGrid");  
  10. </script>  
注意,<body>的class要設(shè)置為對應(yīng)的theme,比如:<body class=“claro">

【DataGrid的一般屬性】
這里我主要使用DOM聲明的方式,當(dāng)然用js定義layout也是可以的。dojo會在window.onload 時(shí)解析 dojoType="dojox.grid.DataGrid" 并讀取相關(guān)屬性設(shè)置并顯示最終的效果。
下面的 <table><thead>...</thead></table> 即為設(shè)計(jì)時(shí)定義 DataGrid 的 layout,運(yùn)行時(shí)被 dojo 解析生成實(shí)際的 HTML。
[javascript] view plaincopy
  1. function getDataStore(count) {  
  2.     var items = [];  
  3.     for(var i=0; i<count; i++) {  
  4.        items.push({  
  5.          f0: false,  
  6.          f1: i%2==0?"field1_ 1 " + i:"1",  
  7.          f2: "field2_" + i,  
  8.          f3: "field3_" + i,  
  9.          f4: "field4_" + i,  
  10.          f5: "field5_" + i,  
  11.          f6: "field6_" + i,  
  12.          f7: "field7_" + i  
  13.        });  
  14.     }  
  15.     var data = new dojo.data.ItemFileWriteStore({data: {items:items}});  
  16.     return data;  
  17. }  
  1. <table dojoType='dojox.grid.DataGrid' id='grid1' jsid='js_grid1'   
  2.  style='border:1px #a8a8a8 solid;width:450px;height:200px;' store="getDataStore(10)"  
  3.  canSort='false' selectionMode='single' >  
  4.  <thead>  
  5.     <tr>  
  6.       <th field="f1" cellStyles="text-align:center;" width="100px" >列1</th>  
  7.       <th field="f2" cellStyles="text-align:center;" width="100px" >列2</th>  
  8.       <th field="f3" cellStyles="text-align:center;" width="100px" >列3</th>  
  9.       <th field="f4" cellStyles="text-align:center;" width="100px" >列4</th>  
  10.       <th field="f5" cellStyles="text-align:center;" width="100px" >列5</th>  
  11.       <th field="f6" cellStyles="text-align:center;" width="100px" >列6</th>  
  12.     </tr>  
  13. </thead>  
  14. </table>  

■DataGrid 屬性(table 里的屬性)
dojoType
: dojox.grid.DataGrid (定義dojo組件的類型,這里當(dāng)然是 dojox.grid.DataGrid 或者是 DataGrid 的繼承類)
structure: js定義的表格
store: 數(shù)據(jù)源,可以是:dojo.data.ItemFileReadStore (只讀),dojo.data.ItemFileWriteStore (可寫)等
selectionMode: 表格的選擇方式:
     none(不選擇),
     single(單行選擇),
    multiple(多選,點(diǎn)一行加一行的選擇),
    extended(擴(kuò)展選擇,按下ctrl鍵+選擇,增加選擇行)(默認(rèn)方式)
sortInfo: 設(shè)置排序的方式:升序,降序
canSort: 可以指定那一列排序或者不能排序
rowHeight: 定義行高,這是一個(gè)重要屬性(對性能有影響)
rowsPerPage: 一次加載的每頁的行數(shù)(默認(rèn): 25行)
columnReordering: 允許拖拽調(diào)整列的順序(默認(rèn): false)

...

■DataGrid的Cell屬性
field
: 對應(yīng)數(shù)據(jù)源里的列
width: 寬度定義,可以用px 或者 %
formatter: 設(shè)定一個(gè) js function,返回 HTML 用于再次編輯顯示內(nèi)容
比如為某列加上個(gè)link:
<th field="f1" formatter="addLink">field1</th>
[javascript] view plaincopy
  1. function addLink(value, index) {  
  2.     return "<a href='javascript:void(0);'>" + value + "</a>";  
  3. }  

styles: 列(表頭和明細(xì))的style定義
headStyles: 表頭的style定義
cellStyles: 明細(xì)的style定義 (正如上面的示例,表頭默認(rèn)左對齊,明細(xì)定義為居中對齊)
classes, headClasses, cellClasses: 同上類似,設(shè)置css class
editable: 列是否可編輯(true/false)
cellType: 可編輯時(shí),設(shè)定對應(yīng)的類型(比如:Checkbox, Select, Date等)
get: js function 返回想要在這個(gè)單元格里需要顯示的值
hidden: 控制該列顯示不顯示(true/false)
...

接下來看看幾種特殊的表格的定義方式:
① 普通的多行組(表頭行數(shù)=明細(xì)行數(shù))


  1. <table dojoType='dojox.grid.DataGrid' id='grid2' jsid='js_grid2'   
  2.  style='border:1px #a8a8a8 solid;width:450px;height:200px;' store="getDataStore(10)"  
  3.  selectionMode='single' >  
  4.  <thead>  
  5.     <tr>  
  6.       <th field="f1"  width="25%" >列1</th>  
  7.       <th field="f2"  width="25%" >列2</th>  
  8.       <th field="f3"  width="25%" >列3</th>  
  9.       <th field="f4"  width="25%" >列4</th>  
  10.     </tr>  
  11.     <tr>  
  12.       <th field="f5" >列5</th>  
  13.       <th field="f6" >列6</th>  
  14.       <th field="f7" >列7</th>  
  15.       <th field="f8" >列8</th>  
  16.     </tr>  
  17. </thead>  
  18. </table>  

② 多行組+合并單元格(rowspan+colspan)(表頭行數(shù)=明細(xì)行數(shù))


  1. <table dojoType='dojox.grid.DataGrid' id='grid3' jsid='js_grid3'   
  2.  style='border:1px #a8a8a8 solid;width:450px;height:200px;' store="getDataStore(10)"  
  3.  selectionMode='single' >  
  4.  <thead>  
  5.     <tr>  
  6.       <th field="f1" rowspan="2" width="25%" >列1</th>  
  7.       <th field="f2" cellStyles="text-align:center;" width="25%" >列2</th>  
  8.       <th field="f4" cellStyles="text-align:center;" width="25%" >列4</th>  
  9.       <th field="f5" cellStyles="text-align:center;" width="25%" >列5</th>  
  10.     </tr>  
  11.     <tr>  
  12.       <th field="f3" cellStyles="text-align:center;" >列3</th>  
  13.       <th field="f6" colspan="2" cellStyles="text-align:center;" >列6</th>  
  14.     </tr>  
  15. </thead>  
  16. </table>  

③ 多行組(表頭行數(shù)<明細(xì)行數(shù):表頭1行,明細(xì)2行一組)
tip: 表頭的一行用headStyle隱藏, 但注意仍會留下一行細(xì)細(xì)的行

  1. <table dojoType='dojox.grid.DataGrid' id='grid4' jsid='js_grid4'   
  2.  style='border:1px #a8a8a8 solid;width:450px;height:200px;' store="getDataStore(10)"  
  3.  selectionMode='single' canSort="false">  
  4.  <thead>  
  5.     <tr>  
  6.       <th field="f1" headStyles="display:hidden" ><div/></th>  
  7.       <th field="f2" headStyles="display:hidden" ><div/></th>  
  8.       <th field="f3" headStyles="display:hidden" ><div/></th>  
  9.       <th field="f4" headStyles="display:hidden" ><div/></th>  
  10.     </tr>  
  11.     <tr>  
  12.       <th field="f1" width="25%">列5</th>  
  13.       <th field="f2" width="25%">列6</th>  
  14.       <th field="f3" width="25%">列7</th>  
  15.       <th field="f4" width="25%">列8</th>  
  16.     </tr>  
  17. </thead>  
  18. </table>  

④ 多行組(表頭行數(shù)>明細(xì)行數(shù):表頭2行,明細(xì)1行)


  1. <table dojoType='dojox.grid.DataGrid' id='grid4' jsid='js_grid4'   
  2.  style='border:1px #a8a8a8 solid;width:450px;height:200px;' store="getDataStore(10)"  
  3.  selectionMode='single' canSort="false">  
  4.  <thead>  
  5.     <tr>  
  6.       <th colspan="2" cellStyles="display:none;">merge 1</th>  
  7.       <th colspan="2" cellStyles="display:none;">merge 2</th>  
  8.     </tr>  
  9.     <tr>  
  10.       <th field="f1" width="25%">列1</th>  
  11.       <th field="f2" width="25%">列2</th>  
  12.       <th field="f3" width="25%">列3</th>  
  13.       <th field="f4" width="25%">列4</th>  
  14.     </tr>  
  15. </thead>  
  16. </table>  

⑤ 設(shè)置固定列
通過  <colgroup> 定義:
<colgroup span="2" noscroll="true"></colgroup>
<colgroup span="5"></colgroup>

如下圖所示,前2列為固定,后面幾列可以滾動(dòng)。


⑥ 多段組+固定列
因?yàn)槎喽谓M的原因,第2行中要增加一個(gè)空列
  1. <table jsId="grid" id="grid5" dojoType="dojox.grid.DataGrid"   
  2.      store="getDataStore(10)" style="width:450px;height:240px;">  
  3.     <colgroup span="1" noscroll="true"></colgroup>  
  4.     <colgroup span="5"></colgroup>  
  5. <thead>  
  6.   <tr>  
  7.     <th rowspan="2" field="f1" width="80px">列1</th>  
  8.     <th field="f2" width="80px">列2</th>  
  9.     <th field="f3" width="80px">列3</th>  
  10.     <th field="f4" width="80px">列4</th>  
  11.     <th field="f5" width="80px">列5</th>  
  12.     <th field="f5" width="80px">列6</th>  
  13.   </tr>  
  14.   <tr>  
  15.     <strong><th styles="display:none;"></th></strong>  
  16.     <th cellstyles="display:none;">列(2)</th>  
  17.     <th cellstyles="display:none;">列(3)</th>  
  18.     <th cellstyles="display:none;">列(4)</th>  
  19.     <th cellstyles="display:none;">列(5)</th>  
  20.     <th cellstyles="display:none;">列(6)</th>  
  21.   </tr>                              
  22. </thead>    
  23. </table>  



-- 本章結(jié)束 --
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Dojo Tips and Tricks - InsideRIA
easyui dataGrid 左右兩個(gè)datagrid 相互移動(dòng)數(shù)據(jù)
Easyui datagrid 顯示隱藏列
jQuery EasyUI DataGrid - 嵌套的DataGrid
轉(zhuǎn)easyui datagrid 前臺分頁的實(shí)現(xiàn)
easyUI中 datagrid 一列字比較多時(shí),出現(xiàn)省略符號
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服