PDA

View Full Version : Problemswith encoding in CellEditingPlugin



fletchergirl
20 Jun 2013, 2:53 AM
I'm working on a project with ExtJs 4.1.4 and Architect 2.2.
I have a grid with a CellEditing Plugin. There is no problem with normal text, JSON sends it as ASCII. But as soon as you use German Umlaut or e.g. Cyrillic letters e.g. '??? ??????', JSON sends it as Unicode.
Even if I set encode to false, the problem still exists.
In php I decode it as


$rows = json_decode(stripslashes($rows), true);

Anyone has the same problem?
Thanks for your help!!

My store:


Ext.define('Format.store.Lines', {
extend: 'Ext.data.Store',

requires: [
'Format.model.Line'
],

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: false,
model: 'Format.model.Line',
storeId: 'Lines',
proxy: {
type: 'ajax',
actionMethods: {
create: 'POST',
read: 'POST',
update: 'POST',
destroy: 'POST'
},
api: {
create: 'data/db/controller.php/create',
read: 'data/db/controller.php/read',
update: 'data/db/controller.php/update',
destroy: 'data/db/controller.php/destroy'
},
reader: {
type: 'json',
idProperty: 'OIP_ID',
messageProperty: 'msg',
root: 'rows'
},
writer: {
type: 'json',
allowSingle: false,
encode: true,
root: 'rows'
}
}
}, cfg)]);
}
});


grid column (talking about the Textfield, not the ComboBox-option):


{
xtype: 'gridcolumn',
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
var st = Ext.getStore('Writings');
var total = st.getCount();
if (record.data.WRITING_EDIT == 1){
return record.data.WRITING;
} else {
index = st.findExact('WRITING_ID',value);
if (index != -1){
rs = st.getAt(index).data;
return rs.WRITING;
} else {
return record.data.WRITING;
}
}
},
getEditor: function(record) {
me = this.up('grid');

//console.log('getEditor of col, this: 1.o', me);
if(record.get('WRITING_EDIT')===1){
return Ext.create('Ext.grid.CellEditor', {
field: Ext.create('Ext.form.field.Text',{
itemId: 'writingField',
emptyText: 'Add a writing'
})
});
} else {
return Ext.create('Ext.grid.CellEditor', {
field: Ext.create('Ext.form.field.ComboBox', {
itemId: 'writingCombo',
editable: false,
displayField: 'WRITING',
forceSelection: true,
store: 'Writings',
valueField: 'WRITING',
listeners: {
focus: {
fn: me.onWritingComboFocus,
scope: me
}
}
})
});
}
},
dataIndex: 'WRITING',
text: 'Writing',
flex: 1
}

fletchergirl
20 Jun 2013, 4:06 AM
When I enter Ext.USE_NATIVE_JSON = true;
in the launch function, it works in FF and Chrome.
IE still has the same problem....
Any ideas? :-?



Ext.application({

requires: [
'Format.view.FormatWin'
],
views: [
'FormatWin'
],
controllers: [
'FormatCtr'
],
name: 'Format',

launch: function() {
Format.g = {};
Ext.USE_NATIVE_JSON = true;
}

});

slemmon
24 Jun 2013, 11:56 AM
From what I can gather XHR only supports UTF-8 and you can also pass unicode characters. It seems that the eval() done by Chrome and FF and modern IE are bit more adept at resolving escaped unicode and such, but older IE browsers suffer.

I did a Google search and saw other having trouble getting their strings serialized to JSON using PHP's native methods and were having to get a bit more creative (or use a PHP library adept at serializing the complex strings). I suspect that will be the next step is getting the string re-serialized in PHP and likely not with just json_decode alone.