PDA

View Full Version : Editable values don't send from Grid Panel to php-script



Shady-sister
28 Jun 2012, 3:26 AM
Hi! I have an editable Grid using php+mysql. When I try to edit cell, I have an empty $_POST.
Scrinshot from firebug (+ result from edit.php with var_dump($_POST)):
36622
36623
view.js:

Ext.onReady(function() { var cols = [
{ dataIndex: 'id', header: 'id', hidden: true },
{ dataIndex: 'title', header: 'Title', width: 200, editor: 'textfield' },
{ dataIndex: 'author', header: 'Author', width: 200, editor: 'textfield' },
{ dataIndex: 'isbn', header: 'ISBN', width: 100, editor: 'numberfield' },
],


fields = [];
for(var i=0; i<cols.length; i++) {
fields.push(cols[i].dataIndex);
}


Ext.define('Book', {
extend: 'Ext.data.Model',
fields: fields
});


var store = Ext.create('Ext.data.JsonStore', {
model: 'Book',
proxy: {
type: 'ajax',
actionMethods: {
create: 'POST',
read: 'POST',
update: 'POST',
destroy: 'POST'
},
api:{
read: 'view.php',
update: 'edit.php'
}},
reader: {
type: 'json'
//root: 'data'
},
writer: new Ext.data.writer.Json({
writeAllFields: true
})

});


Ext.create('Ext.grid.Panel', {
columns: cols,
tbar: [
{
text: 'Save',
handler: function(){
//var up = getUpdatedRecords();
store.sync()
}
}
],


width: 520,
style: 'margin-top: 5%; margin-left: 35%',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
renderTo: Ext.getBody(),
store: store
});
store.load();


});




view.php

<?php
require_once 'db.php';
$result = mysql_query('SELECT * FROM books');
while ($row = mysql_fetch_assoc($result)) {
for ($i=0; $i < mysql_num_fields($result); $i++) {
$meta = mysql_fetch_field($result, $i); }
$rows[] = $row;
}
print (json_encode($rows));

?>

edit.php

<?php
require_once 'db.php';
ini_set('display_errors', 1);error_reporting(E_ALL);
var_dump($_POST);?>

Help me please with my problem! Thank you.

Shady-sister
28 Jun 2012, 5:12 AM
Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 2, listeners: { 'edit': function (editor,e) { var grid = e.grid; var record = e.record; /*console.log(record.data.id); console.log(record.data.title); console.log(record.data.author); console.log(record.data.isbn); var res = []; res.push(record.data.id); res.push(record.data.title); res.push(record.data.author); res.push(record.data.isbn); console.log(res);*/ Ext.Ajax.request({ url: 'edit.php', method: 'POST', params: { id: record.data.id, title: record.data.title, author: record.data.author, isbn: record.data.isbn } } )} }