使用php和jason的Extjs Grid [英] Extjs Grid using php and jason

查看:48
本文介绍了使用php和jason的Extjs Grid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql中有一个简单的数据,想在Extjs网格中填充该数据

我的代码

extjson-grid.html

I have a simple data in mysql and want to populate that data in a Extjs grid

My code

extjson-grid.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>



connectextjs.php



connectextjs.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);


?>




extjson-grid.js




extjson-grid.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
    });

});



我的问题是我无法在网格上加载数据.请帮助我,我是Extjs的新手

谢谢



My problem is I can''t load the data on the grid. Please help me I am new to Extjs

Thanks

推荐答案

result = mysql_query("SELECT * FROM Employees") 或die(mysql_error());
result = mysql_query("SELECT * FROM employees") or die(mysql_error());


row = mysql_fetch_assoc(
row = mysql_fetch_assoc(


result); //获取数据并存储在json数组中
result); // get data and store in a json array


这篇关于使用php和jason的Extjs Grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆