jQuery EasyUI 數據網格 – 使用虛擬滾動視圖顯示海量數據

2022-06-08 16:23 更新

jQuery EasyUI 數據網格 - 使用虛擬滾動視圖顯示海量數據

jQuery EasyUI數據網格(datagrid)可以使用虛擬滾動視圖來顯示大數量的記錄而不需要分頁。滾動垂直滾動條,數據網格將執(zhí)行ajax請求以加載和刷新現有的記錄;整個刷新的行為過程是平穩(wěn)的沒有閃爍。 

在本節(jié)示例中,我們將創(chuàng)建一個數據網格,并運用虛擬滾動特性從服務器加載數據。

創(chuàng)建數據網格(DataGrid)

為數據網格運用虛擬滾動特性,'view'屬性應該設置為'scrollview'。用戶應該從數據網格擴展下載scrollview,并在頁面頭部引用scrollview文件。

<script type="text/javascript" src="http://m.hgci.cn/try/jeasyui/datagrid-detailview.js"></script>
<table id="tt" class="easyui-datagrid" style="width:700px;height:300px" title="DataGrid - VirtualScrollView" data-options="view:scrollview,rownumbers:true,singleSelect:true,url:'datagrid27_getdata.php',autoRowHeight:false,pageSize:50">
	<thead>
		<tr>
			<th field="inv" width="80">Inv No</th>
			<th field="date" width="100">Date</th>
			<th field="name" width="80">Name</th>
			<th field="amount" width="80" align="right">Amount</th>
			<th field="price" width="80" align="right">Price</th>
			<th field="cost" width="100" align="right">Cost</th>
			<th field="note" width="110">Note</th>
		</tr>
	</thead>
</table>

請注意,這里我們不需要使用pagination屬性,但pageSize屬性是必需的,這樣執(zhí)行ajax請求時,數據網格(datagrid)將從服務器獲取指定數量的記錄。

服務器端代碼

datagrid27_getdata.php

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 50;

$items = array();
date_default_timezone_set('UTC');
for($i=1; $i<=$rows; $i++){ 	$index = $i+($page-1)*$rows; 	$amount = rand(50,100); 	$price = rand(10000,20000)/100; 	$items[] = array( 		'inv' => sprintf("INV%04d",$index),
		'date' => date('Y-m-d',time()+24*3600*$i),
		'name' => 'Name' . $index,
		'note' => 'Note' . $index,
		'amount' => $amount,
		'price' => sprintf('%01.2f',$price),
		'cost' => sprintf('%01.2f',$amount*$price)
	);
}
$result = array();
$result['total'] = 8000;
$result['rows'] = $items;
echo json_encode($result);

下載 jQuery EasyUI 實例

jeasyui-datagrid-datagrid27.zip

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號