亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery EasyUI中文參考手冊 / jEasyUI 創(chuàng)建 CRUD 數(shù)據(jù)網(wǎng)格

jEasyUI 創(chuàng)建 CRUD 數(shù)據(jù)網(wǎng)格

在上一章節(jié)中,我們使用對話框(dialog)組件創(chuàng)建了 CRUD 應(yīng)用來創(chuàng)建和編輯用戶信息。本教程我們將告訴您如何創(chuàng)建一個 CRUD 數(shù)據(jù)網(wǎng)格(DataGrid)。 我們將使用 可編輯的數(shù)據(jù)網(wǎng)格(DataGrid)插件 來完成這些 CRUD 操作動作。

17.png

步驟 1:在 HTML 標(biāo)簽中定義數(shù)據(jù)網(wǎng)格(DataGrid)

<table id="dg" title="My Users" style="width:550px;height:250px"
		toolbar="#toolbar" idField="id"
		rownumbers="true" fitColumns="true" singleSelect="true">
	<thead>
		<tr>
			<th field="firstname" width="50" editor="{type:'validatebox',options:{required:true}}">First Name</th>
			<th field="lastname" width="50" editor="{type:'validatebox',options:{required:true}}">Last Name</th>
			<th field="phone" width="50" editor="text">Phone</th>
			<th field="email" width="50" editor="{type:'validatebox',options:{validType:'email'}}">Email</th>
		</tr>
	</thead>
</table>
<div id="toolbar">
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">New</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">Destroy</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">Save</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">Cancel</a>
</div>

步驟 2:使用可編輯的數(shù)據(jù)網(wǎng)格(DataGrid)

$('#dg').edatagrid({
	url: 'get_users.php',
	saveUrl: 'save_user.php',
	updateUrl: 'update_user.php',
	destroyUrl: 'destroy_user.php'
});

我們應(yīng)該提供 'url'、'saveUrl'、'updateUrl' 和 'destroyUrl' 屬性來編輯數(shù)據(jù)網(wǎng)格(DataGrid):

  • url:從服務(wù)器端檢索用戶數(shù)據(jù)。

  • saveUrl:保存一個新的用戶數(shù)據(jù)。

  • updateUrl:更新一個已存在的用戶數(shù)據(jù)。

  • destroyUrl:刪除一個已存在的用戶數(shù)據(jù)。

步驟 3:寫服務(wù)器處理代碼

保存一個新的用戶(save_user.php):

$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];

include 'conn.php';

$sql = "insert into users(firstname,lastname,phone,email) values('$firstname','$lastname','$phone','$email')";
@mysql_query($sql);
echo json_encode(array(
	'id' => mysql_insert_id(),
	'firstname' => $firstname,
	'lastname' => $lastname,
	'phone' => $phone,
	'email' => $email
));

更新一個已存在用戶(update_user.php):

$id = intval($_REQUEST['id']);
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];

include 'conn.php';

$sql="update users set firstname='$firstname',lastname='$lastname',phone='$phone',email='$email' where id=$id";
@mysql_query($sql);
echo json_encode(array(
	'id' => $id,
	'firstname' => $firstname,
	'lastname' => $lastname,
	'phone' => $phone,
	'email' => $email
));

刪除一個已存在用戶(destroy_user.php):

$id = intval($_REQUEST['id']);

include 'conn.php';

$sql = "delete from users where id=$id";
@mysql_query($sql);
echo json_encode(array('success'=>true));

下載 jQuery EasyUI 實(shí)例

jeasyui-app-crud2.zip