php表格展开行,数据表格中展开行显示详情

数据表格中展开行显示详情

使用教程 » 数据表格中展开行显示详情

datagrid可以更改视图以显示不同的效果。

使用detail视图,datagrid可以在数据行左侧显示展开按钮(“+”或“-”)。

用户可以展开一行以显示其他详细信息。

12f4443b63e2f790424d5535db9d612d.png

步骤一: 创建数据表格

Item ID

Product ID

List Price

Unit Cost

Status

步骤二: 为DataGrid设置详细视图

要使用detail视图,请记住将视图脚本文件包含到页眉中.

$('#dg').datagrid({

view: detailview,

detailFormatter:function(index,row){

return '

';

},

onExpandRow: function(index,row){

var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv');

ddv.panel({

border:false,

cache:false,

href:'datagrid21_getdetail.php?itemid='+row.itemid,

onLoad:function(){

$('#dg').datagrid('fixDetailRowHeight',index);

}

});

$('#dg').datagrid('fixDetailRowHeight',index);

}

});

我们定义了'detailFormatter'函数来告诉datagrid如何呈现细节视图。

在本例中,我们返回一个简单的div元素,它将充当详细内容容器。

请注意,详细内容是空的。当用户单击expand按钮('+')时,将触发'onExpandRow'事件。

因此,我们可以编写一些代码来加载ajax细节内容。

最后,我们调用'fixDetailRowHeight'方法来固定加载细节内容时的行高度。

步骤三:服务器代码

datagrid21_getdetail.php

include_once 'conn.php';

$itemid = mysql_real_escape_string($_REQUEST['itemid']);

$rs = mysql_query("select * from item where itemid='$itemid'");

$item = mysql_fetch_array($rs);

?>

$aa = explode('-',$itemid);

$serno = $aa[1];

$img = "images/shirt$serno.gif";

echo "

%5C%22%24img%5C%22";

?>

Item ID:

Product ID:

List Price:

Unit Cost:

Attribute:

下载 EasyUI 实例:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 HTML 和 PHP 来实现在表格添加一,并将所选数据插入到数据库。以下是一个简单的例子: 1. 创建一个包含表格和表单的 HTML 文件。 ```html <!DOCTYPE html> <html> <head> <title>Add Row to Table</title> </head> <body> <h1>Add Row to Table</h1> <form action="add_row.php" method="POST"> <label for="name">Name:</label> <input type="text" id="name" name="name"> <label for="age">Age:</label> <input type="number" id="age" name="age"> <input type="submit" value="Add Row"> </form> <table> <tr> <th>Name</th> <th>Age</th> </tr> <?php // Display existing rows from the database $conn = mysqli_connect("localhost", "username", "password", "database"); $query = "SELECT * FROM table_name"; $result = mysqli_query($conn, $query); while ($row = mysqli_fetch_assoc($result)) { echo "<tr><td>" . $row['name'] . "</td><td>" . $row['age'] . "</td></tr>"; } ?> </table> </body> </html> ``` 2. 创建一个 PHP 文件,用于处理表单提交并将数据插入到数据库。 ```php <?php // Get form data $name = $_POST['name']; $age = $_POST['age']; // Insert data into database $conn = mysqli_connect("localhost", "username", "password", "database"); $query = "INSERT INTO table_name (name, age) VALUES ('$name', $age)"; mysqli_query($conn, $query); // Redirect back to the HTML page header("Location: index.html"); exit(); ?> ``` 当用户在表单输入名称和年龄并提交表单时,PHP 文件将插入新到数据库,并将用户重定向回 HTML 页面,显示更新后的表格

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值