http://www.runoob.com/jeasyui/jeasyui-app-crud3.html

jQuery EasyUI 应用 - 创建展开行明细编辑表单的 CRUD 应用

当切换数据网格视图(datagrid view)到 'detailview',用户可以展开一行来显示一些行的明细在行下面。这个功能允许您为防止在明细行面板(panel)中的编辑表单(form)提供 一些合适的布局(layout)。在本教程中,我们使用数据网格(datagrid)组件来减小编辑表单(form)所占据空间。


步骤 1:在 HTML 标签中定义数据网格(DataGrid)

<table id="dg" title="My Users" style="width:550px;height:250px" 		url="get_users.php" 		toolbar="#toolbar" 		fitColumns="true" singleSelect="true"> 	<thead> 		<tr> 			<th field="firstname" width="50">First Name</th> 			<th field="lastname" width="50">Last Name</th> 			<th field="phone" width="50">Phone</th> 			<th field="email" width="50">Email</th> 		</tr> 	</thead> </table> <div id="toolbar"> 	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">New</a> 	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem()">Destroy</a> </div>

步骤 2:为数据网格(DataGrid)应用明细视图

$('#dg').datagrid({ 	view: detailview, 	detailFormatter:function(index,row){ 		return '<div class="ddv"></div>'; 	}, 	onExpandRow: function(index,row){ 		var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv'); 		ddv.panel({ 			border:false, 			cache:true, 			href:'show_form.php?index='+index, 			onLoad:function(){ 				$('#dg').datagrid('fixDetailRowHeight',index); 				$('#dg').datagrid('selectRow',index); 				$('#dg').datagrid('getRowDetail',index).find('form').form('load',row); 			} 		}); 		$('#dg').datagrid('fixDetailRowHeight',index); 	} });

为了为数据网格(DataGrid)应用明细视图,在 html 页面头部引入 'datagrid-detailview.js' 文件。

我们使用 'detailFormatter' 函数来生成行明细内容。 在这种情况下,我们返回一个用于放置编辑表单(form)的空的 <div>。 当用户点击行展开按钮('+')时,'onExpandRow' 事件将被触发,我们将通过 ajax 加载编辑表单(form)。 调用 'getRowDetail' 方法来得到行明细容器,所以我们能查找到行明细面板(panel)。 在行明细中创建面板(panel),加载从 'show_form.php' 返回的编辑表单(form)。

步骤 3:创建编辑表单(Form)

编辑表单(form)是从服务器加载的。

show_form.php
<form method="post"> 	<table class="dv-table" style="width:100%;background:#fafafa;padding:5px;margin-top:5px;"> 		<tr> 			<td>First Name</td> 			<td><input name="firstname" class="easyui-validatebox" required="true"></input></td> 			<td>Last Name</td> 			<td><input name="lastname" class="easyui-validatebox" required="true"></input></td> 		</tr> 		<tr> 			<td>Phone</td> 			<td><input name="phone"></input></td> 			<td>Email</td> 			<td><input name="email" class="easyui-validatebox" validType="email"></input></td> 		</tr> 	</table> 	<div style="padding:5px 0;text-align:right;padding-right:30px"> 		<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="saveItem(&lt;?php echo $_REQUEST['index'];?&gt;)">Save</a> 		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="cancelItem(&lt;?php echo $_REQUEST['index'];?&gt;)">Cancel</a> 	</div> </form>

步骤 4:保存或取消编辑

调用 'saveItem' 函数来保存一个用户或者调用 'cancelItem' 函数来取消编辑。

function saveItem(index){ 	var row = $('#dg').datagrid('getRows')[index]; 	var url = row.isNewRecord ? 'save_user.php' : 'update_user.php?id='+row.id; 	$('#dg').datagrid('getRowDetail',index).find('form').form('submit',{ 		url: url, 		onSubmit: function(){ 			return $(this).form('validate'); 		}, 		success: function(data){ 			data = eval('('+data+')'); 			data.isNewRecord = false; 			$('#dg').datagrid('collapseRow',index); 			$('#dg').datagrid('updateRow',{ 				index: index, 				row: data 			}); 		} 	}); }

决定要回传哪一个 URL,然后查找表单(form)对象,并调用 'submit' 方法来提交表单(form)数据。当保存数据成功时,折叠并更新行数据。

function cancelItem(index){ 	var row = $('#dg').datagrid('getRows')[index]; 	if (row.isNewRecord){ 		$('#dg').datagrid('deleteRow',index); 	} else { 		$('#dg').datagrid('collapseRow',index); 	} }

当取消编辑动作时,如果该行是新行而且还没有保存,直接删除该行,否则折叠该行。

下载 jQuery EasyUI 实例

jeasyui-app-crud3.zip

创建展开行明细编辑表单的 CRUD 应用的更多相关文章

  1. 【jQuery EasyUI系列】 创建展开行明细编辑表单的CRUD应用

    当切换数据网络格局(datagrid view)到detailview,用户可以展开一行来显示一些行的明细在行下面,这个功能允许您为防止在明细行面板中的编辑表单提供一些合适的布局. 步骤1.在HTML ...

  2. 3、easyUI-创建 CRUD可创建展开行明细编辑dataGrid(表格)

    同样在上一节中讲到可以编辑的表格,现在讲一般用到的最后一个datagrid(表格)相关的展开明细可编辑的表格: 第三中表格主要应用场景在:列出表格信息,然后点击可以查看详细信息(此处是全部可以编辑,可 ...

  3. ASP.NET MVC 音乐商店 - 5. 通过支架创建编辑表单

    在上一章,我们已经从数据库获取数据,然后显示出来,这一章,我们将允许编辑数据. 创建 StoreManagerController 控制器 我们将要创建称为 StoreManager 的控制器,对于这 ...

  4. C# Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面

    个人理解,开发应用程序的目的,不论是B/S或是C/S结构类型,无非就是实现可供用户进行查.增.改.删,其中查询用到最多,开发设计的场景也最为复杂,包括但不限于:表格记录查询.报表查询.导出文件查询等等 ...

  5. Winform 通过FlowLayoutPanel及自定义的编辑控件,实现快速构建C/S版的编辑表单页面 z

    http://www.cnblogs.com/zuowj/p/4504130.html 不论是B/S或是C/S结构类型,无非就是实现可供用户进行查.增.改.删,其中查询用到最多,开发设计的场景 也最为 ...

  6. [Swift通天遁地]二、表格表单-(9)快速创建一个美观强大的表单

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. 怎样利用WordPress创建自己定义注冊表单插件

    来源:http://www.ido321.com/1031.html 原文:Creating a Custom WordPress Registration Form Plugin 译文:创建一个定制 ...

  8. ASP.NET Core Razor 编辑表单 - ASP.NET Core 基础教程 - 简单教程,简单编程

    原文:ASP.NET Core Razor 编辑表单 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core Razor 编辑表单 上一章节我们介绍了标签助手和 HT ...

  9. windev中编辑表单确认按钮的code规范建议

    编辑表单的确认操作,是一个常规操作,根据过往经验,建议按以下规范代码来撸.案例如下所示(主子表保存): //填报规范:必填项目 IF COMBO_招聘职位 = "" OR COMB ...

随机推荐

  1. 在程序内部跳转到下一个页面 和 向另一个servlet发起跳转

    request.getRequestDispatcher("/success.html").forward(request,response); request.getReques ...

  2. vector 基础2

    size  :返回有效元素个数 max_size  :返回 vector 支持的最大元素个数 resize  :改变有效元素的个数 capacity  :返回当前可使用的最大元素内存块数(即存储容量) ...

  3. 一个JavaScript日期格式化扩展函数

    我们都知道在Java和PHP语言中,有专门用于格式化日期对象的类和函数,例如Java中的DateFormat等等,通过这些类和函数,我们可以方便的将一个日期对象按照格式的要求输出为字符串,例如对于同一 ...

  4. ubuntu下使用sudo 出现unable to resolve host 解决方法

    Linux 环境, 假设这台机器名字叫dev(机器的hostname), 每次执行sudo 就出现这个警告讯息:sudo: unable to resolve host dev虽然sudo 还是可以正 ...

  5. DP---背包问题

    http://www.hawstein.com/posts/dp-knapsack.html http://www.cnblogs.com/wwwjieo0/archive/2013/04/01/29 ...

  6. RGB颜色原理

    参考:http://www.cnblogs.com/harrytian/archive/2012/12/12/2814210.html 工作中经常和颜色打交道,但却从来没有从原理上了解一下,这篇文章希 ...

  7. Chrome 本地通信

    http://blog.csdn.net/ztmaster/article/details/52684772

  8. 【SPOJ - QTREE2】树链剖分

    http://acm.hust.edu.cn/vjudge/problem/19960 题意: 有一棵N个节点的树(1<=N<=10000),N-1条边,边的编号为1~N-1,每条边有一个 ...

  9. HDU 1840 Equations (数学)

    title: Equations 数学 杭电1840 tags: [数学] 题目链接 Problem Description All the problems in this contest tota ...

  10. jquery with ajax

    with session storage: 1.ajax请求可以放在 $(document).ready(function (){...}); 里. 2. $.ajax({ url: "/a ...