PDA

View Full Version : roweditor with mysql and php



evang
18 May 2010, 9:34 PM
please help. what's wrong with my code? because only read can work properly. create, update, delete won't work with mysql. any suggestions please? thx.



Ext.onReady(function () {
Ext.QuickTips.init();
var Employee = Ext.data.Record.create([{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
},
{
name: 'date',
type: 'date',
dateFormat: 'Y-m-d'
}]);
var store = new Ext.data.GroupingStore({
url: 'view.php',
baseParams: {
// action: "read",
limit: 20,
start: 0,
// sort: "name",
// dir: "ASC"
},
reader: new Ext.data.JsonReader({
fields: Employee,
root: 'rows',
totalProperty: 'total',
idProperty: 'id',
}),
autoLoad: true,
autoSave: true,
autoDestroy: true,
sortInfo: {
field: 'name',
direction: 'ASC'
},
groupField: 'name'
});
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update',
listeners: {
afteredit: function () {
var jsonData = new Array();
for (i = 0; i < store.getCount(); i++) {
record = store.getAt(i);
jsonData.push(record.data);
}
jsonData = Ext.encode(jsonData);
Ext.Ajax.request({
url: 'crud.php?action=update',
params: {
data: jsonData
},
success: function (responce, action) {
//store.loadData(Ext.decode(responce.responseText) );
//alert('Congrats! Your changes were saved!!!!');
},
failure: function (form, action) {
alert('Oops the delete did not work out too well!');
}
});
}
}
});
var userColumns = [
new Ext.grid.RowNumberer(), {
header: "ID",
dataIndex: 'id',
hidden: true,
},
{
header: "Name",
width: 50,
sortable: true,
dataIndex: 'name',
editor: new Ext.form.TextField({})
},
{
header: "Date",
width: 100,
sortable: true,
dataIndex: 'date',
xtype: 'datecolumn',
format: 'd/m/Y',
groupRenderer: Ext.util.Format.dateRenderer('M y'),
editor: {
xtype: 'datefield',
format: 'Y-m-d',
//minValue: '01/01/2000',
//minText: 'Can\'t have a start date before 2010!',
maxValue: (new Date()).format('m/d/Y'),
disabledDays: [0, 7],
disabledDaysText: 'Closed on this day'
}
}];
var userGrid = Ext.extend(Ext.grid.GridPanel, {
initComponent: function () {
Ext.apply(this, {
border: false,
stripeRows: true,
loadMask: true,
autoScroll: true,
store: store,
region: 'center',
//margins: '0 5 5 5',
autoExpandColumn: 'name',
plugins: [editor],
view: new Ext.grid.GroupingView({
forceFit: true,
markDirty: false,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
viewConfig: {
forceFit: true
},
fbar: ['->', {
text: 'Clear Grouping',
iconCls: 'icon-clear-group',
handler: function () {
store.clearGrouping();
}
}],
bbar: new Ext.PagingToolbar({ // paging bar on the bottom
pageSize: 20,
store: store,
displayInfo: true,
plugins: new Ext.ux.ProgressBarPager(),
//displayMsg: 'Displaying items {0} - {1} of {2}',
//emptyMsg: "No items to display"
}),
tbar: [{
icon: 'Scripts/table_add.png',
cls: 'x-btn-text-icon',
text: 'Add',
scope: this,
handler: function () {
Ext.Ajax.request({
url: 'crud.php?action=insert',
scope: this,
success: function (resp, opt) {
editor.stopEditing();
var insert_id = Ext.util.JSON.decode(resp.responseText).insert_id;
store.insert(0, new Employee({
id: insert_id,
name: '',
date: ''
}));
this.getView().refresh();
this.getSelectionModel().selectRow(0);
editor.startEditing(0);
}
});
}
},
'-', {
icon: 'Scripts/table_delete.png',
cls: 'x-btn-text-icon',
text: 'Delete',
scope: this,
handler: function () {
editor.stopEditing();
var s = this.getSelectionModel().getSelections();
for (var i = 0, r; r = s[i]; i++) {
Ext.Ajax.request({
url: 'crud.php?action=delete',
params: {
id: r.data.id
},
success: function (responce, action) {
store.remove(r);
//alert('Congrats! Your changes were saved!!!!');
}
});
}
}
},
'-'],
columns: userColumns,
});
userGrid.superclass.initComponent.call(this);
}
});
Ext.reg('grid', userGrid);
});

Condor
18 May 2010, 11:25 PM
1. Define "won't work".
2. Why are you not using Ext.direct?

evang
24 May 2010, 6:47 AM
1. Define "won't work".
2. Why are you not using Ext.direct?

yap, I would like to using Ext.direct but still can't find any simple example based on mysql php to use it with row editor function. please please help :((

steffenk
24 May 2010, 7:33 AM
then you didn't searched. There is something in Examples forum.