是否可以给出 extjs Editorgridpanel 从 php 获取数据的工作示例,我找到了一些示例,但它们对我不起作用
我试过了,这个,有什么问题
我的 html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>JSON Grid Example</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
<script type="text/javascript" src="adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-all.js"></script>
<link rel="stylesheet" type="text/css" href="examples/grid/grid-examples.css" />
<script type="text/javascript" src="extjson-grid.js"></script>
<h1>JSON Grid Example</h1>
<p>This example shows how to load a grid with JSON data.</p>
<div id="example-grid"></div>
</head>
</html>
我的js
Ext.onReady(function(){
var proxy=new Ext.data.HttpProxy({url:'connectextjs.php'});
var reader=new Ext.data.JsonReader(
[{name: 'Employee_ID', mapping: 'Employee_ID'},
{name: 'Department_ID'},
{name: 'Name'},
{name: 'Email'}]
var store = new Ext.data.Store({proxy:proxy,reader:reader});
store.load();
create the grid var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: "Employee_ID", width: 90, dataIndex: 'Employee_ID', sortable: true},
{header: "Department_ID", width: 90, dataIndex: 'Department_ID', sortable: true},
{header: "Name", width: 90, dataIndex: 'Name', sortable: true},
{header: "Email", width: 200, dataIndex: 'Email', sortable: true}],
renderTo:'example-grid',
width:540, height:200
});
});
我的PHP代码
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
// Retrieve all the data from the "employee" table
$result = mysql_query("SELECT * FROM employees") or die(mysql_error());
$row = mysql_fetch_assoc($result);
// get data and store in a json array
$query ="Select Employee_ID,Department_ID,Name,Email from Employees";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ $myInventory[] = array(
'Employee_ID' => $row['Employee_ID'],
'Department_ID' => $row['Department_ID'],
'Name' => $row['Name'],
'Email' => $row['Email'] ; }
$myData = $myInventory;
echo json_encode($myData);
?>