easyui實現表格分頁操作「easyui分頁查詢」

本教程展示如何在帶有動態加載特性的樹網格中添加分頁。

jQuery EasyUI使用教程:添加分頁到樹網格中

創建樹網格

想要啟動樹網格的分頁功能,首先必須添加 ‘pagination:true’ 屬性,這樣頁面加載時就會向服務器發送 ‘page’ 和 ‘rows’ 參數。

NameQuantityPriceTotal

服務器代碼

treegrid4_getdata.php

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;

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

include 'conn.php';

$result = array;
if ($id == 0){
$rs = mysql_query("select count(*) from products where parentId=0");
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];

$rs = mysql_query("select * from products where parentId=0 limit $offset,$rows");
$items = array;
while($row = mysql_fetch_array($rs)){
$row['state'] = has_child($row['id']) ? 'closed' : 'open';
array_push($items, $row);
}
$result["rows"] = $items;
} else {
$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;
}

發送到服務器的參數包括:

當展開一個行節點時,’id’ 值是大於 0 的。 當改變頁碼時,’id’ 值應該被設置為 0 來放置加載子行。

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/250143.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-13 13:29
下一篇 2024-12-13 13:29

相關推薦

發表回復

登錄後才能評論