jQuery EasyUI使用教程之在樹網格中動態加載

動態加載樹網格有助於從服務器上加載部分的行數據,避免加載大型數據的長時間等待。本教程將向您展現如何建立具備動態加載特性的樹網格。php

jQuery EasyUI最新試用版下載請猛戳>>html

添加節點到樹形菜單

點擊查看示例mysql

建立樹網格

1sql

2json

3服務器

4fetch

5ui

6url

7spa

8

9

10

<table title="Products" class="easyui-treegrid" style="width:700px;height:300px" url="treegrid3_getdata.php" rownumbers="true" idfield="id" treefield="name">

<thead>

<tr>

<th field="name" width="250">Name</th>

<th field="quantity" width="100" align="right">Quantity</th>

<th field="price" width="150" align="right" formatter="formatDollar">Price</th>

<th field="total" width="150" align="right" formatter="formatDollar">Total</th>

</tr>

</thead>

</table>

服務器代碼

treegrid3_getdata.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

$id = isset($_POST['id']) ? intval($_POST['id']) : 0;

 

include 'conn.php';

$result = array();

$rs = mysql_query("select * from products where parentId=$id");

while($row = mysql_fetch_array($rs)){

$row['state'] = has_child($row['id']) ? 'closed' 'open';

$row['total'] = $row['price']*$row['quantity'];

array_push($result, $row);

}

 

echo json_encode($result);

 

function has_child($id){

$rs = mysql_query("select count(*) from products where parentId=$id");

$row = mysql_fetch_array($rs);

return $row[0] > 0 ? true false;

}

下載EasyUI示例:easyui-treegrid-demo.zip

有興趣的朋友能夠點擊查看更多有關jQuery EasyUI的教程>>

相關文章
相關標籤/搜索