PDA

View Full Version : GridPanel Store with PHP + MySql Table



muceli
25 Jul 2013, 3:38 PM
Turning to the database records. However, do not store the object records.

45051

+ app
+view
-Main.js
+store
-ListeStore.js
model
+data
store.php // database connection and sql query
+extjs // ext js library
app.js
index.php

data/store.php



<?php
function getList() {
$connect= mysql_connect("localhost", "root","");
$db = mysql_select_db("crud_extjs4", $connect) or die("error");
$query= mysql_query("select userID, name, lastname, age from users");
$i = 0;
while($result= mysql_fetch_assoc($query)) {
$data["liste"][$i] = $result;
$i++;
};
$json = json_encode($data);
return $json;
}
echo getList();
?>


app/view/Main.js



Ext.define('PHPExtJS4.view.Main',{
extend: 'Ext.grid.Panel',
alias : 'widget.Liste',
id:'myList',
title: 'Liste',
padding: '20',
store: 'ListeStore',
columns: [
{ id: 'userID', header: "Id", width: 50, sortable: true, dataIndex: 'userID' },
{ id:'name', header: "User Name", width: 75, sortable: true, dataIndex: 'name' },
{ id:'lastname', header: "User LastName", width: 75, sortable: true, dataIndex: 'lastname' },
{ id:'age', header: "User Age", width: 75, sortable: true, dataIndex: 'age' }
]
});


app/store/ListeStore.js



Ext.define('PHPExtJS4.store.ListeStore', {
extend: 'Ext.data.JsonStore',
proxy: {
type: 'ajax',
url: 'data/store.php',
reader: {
type: 'json',
root: 'liste'
}
}
fields: ['userID', 'name', 'lastname', 'age']
});

Renan Cunha
25 Jul 2013, 4:38 PM
The Ext JS made the request to the server? You already debugged the result using some tool like Chrome Developer Tools or Firebug?

muceli
26 Jul 2013, 12:43 AM
"Uncaught TypeError: Cannot read property 'buffered' of undefined" it gave an error message