學習easyui疑問(三),學習easyui疑問
今天我學習easyui中碰到的另一問題是:如何建立一個表格?
首先,在easyui中文官網上提供的這樣一種定義方式:
<!--table--><table id="tt"></table>
<!--script-->$('#tt').datagrid({ url:'datagrid_data.json', /*這裡用於傳資料*/ columns:[[ {field:'code',title:'Code',width:100}, {field:'name',title:'Name',width:100},//需要特別注意這裡沒有所謂的單位 {field:'price',title:'Price',width:100,align:'right'} ]]});
這種方式只能用於建立的datagrid(也就是我們所說的table):
而不能達到我所想要打有一定格式的excel表效果。如下:
也就是說我想要自訂表格格格式,這在html中直接用table來寫還是比較容易實現的,但為了table的樣式美觀性,用到easyui,我們就必須換種方式來寫。
接下來,我就給大家介紹一下解決這個問題的方式—在table中進行建立
代碼如下:
1 <table class="easyui-datagrid" style="width:400px;height:250px" 2 data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true"> 3 <thead> 4 <tr> 5 <th data-options="field:'code',width:100">Code</th> 6 <th data-options="field:'name',width:100">Name</th> 7 <th data-options="field:'price',width:100,align:'right'">Price</th> 8 </tr> 9 </thead> 10 </table>
如下:
貼一下我的table代碼:
<table class="easyui-datagrid" style="width: 300px; height: 200px;" data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true"> <!--url這裡並無卵用--> <thead> <tr> <th data-options="field:'code',width:100"> Code </th> <th data-options="field:'name',width:100"> Name </th> <th data-options="field:'price',width:100,align:'right'"> Price </th> </tr> </thead> <tfoot> </tfoot> <tbody> <tr> <td> _code </td> <td> _name </td> <td> _price </td> </tr> </tbody> </table>
這樣我們就既比較容易建立table格式,又可以應用easyui的ui介面了。贊一個!!
望此文能協助你!
分享萬歲!!
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。