PDA

View Full Version : How to remove special char sending query to ajax store



dmartin
20 Dec 2012, 6:17 AM
Hi,

I have a store, form, search field and grid working perfectly excpet that I don't know how to catch the refresh event to remove the potential special char ....

Any help would be welcomed.

D


Ext.define('LibPublilex', {
extend: 'Ext.data.Model',
fields: [
{
name: 'Abrev',
mapping: 'Abrev'
}, {
name: 'Title',
mapping: 'Title'
}, {
name: 'Art',
type: 'int'
}
],
idProperty: 'book_id'
});

// create the Data Store
var pstore = Ext.create('Ext.data.Store', {
id: 'pstore',
model: 'LibPublilex',
// allow the grid to interact with the paging scroller by buffering
buffered: true,

// The topics-remote.php script appears to be hardcoded to use 50, and ignores this parameter, so we
// are forced to use 50 here instead of a possibly more efficient value.
pageSize: 50,

// This web service seems slow, so keep lots of data in the pipeline ahead!
leadingBufferZone: 1000,
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
type: 'ajax',
async : false,
url: 'php/ajax_get_books.php',
reader: {
root: 'items',
totalProperty: 'TotalCount'
},
// sends single sort as multi parameter
simpleSortMode: true,

// Parameter name to send filtering information in
filterParam: 'query',

// The PHP script just use query=<whatever>
encodeFilters: function(filters) {
return filters[0].value;
}
},
listeners: {
totalcountchange: onStoreSizeChangep
},
remoteFilter: true,
autoLoad: true
});

function onStoreSizeChangep() {
grid.down('#status').update({count: pstore.getTotalCount()});
}

function columnWrap(val){
ss = grid.down('#psearch').getValue();

tt = ss.split(' ');

for (var i = 0; i < tt.length; i++) {
if(i==0)
{
tval = val.replace(tt[i],'<span class="y">' + tt[i] + '</span>');
cap = tt[i].substr(0,1).toUpperCase() + tt[i].substr(1).toLowerCase();
tval = tval.replace(cap,'<span class="y">' + cap + '</span>');
min = tt[i].substr(0,1).toLowerCase() + tt[i].substr(1).toLowerCase();
tval = tval.replace(min,'<span class="y">' + min + '</span>');
}
else
{
tval = tval.replace(tt[i],'<span class="y">' + tt[i] + '</span>');
cap = tt[i].substr(0,1).toUpperCase() + tt[i].substr(1).toLowerCase();
tval = tval.replace(cap,'<span class="y">' + cap + '</span>');
min = tt[i].substr(0,1).toLowerCase() + tt[i].substr(1).toLowerCase();
tval = tval.replace(min,'<span class="y">' + min + '</span>');
}
}

return '<div style="white-space:normal;">'+ tval +'</div>';
}


var grid = Ext.widget('form', {
renderTo: 'col1',
id:'tip_lib',
frame: true,
width: 420,
height: 550,
margin: '0 0 0 0',
bodyPadding: 10,
bodyBorder: false,
title: 'Librairie Publilex',
defaults: {
anchor: '100%'
},
fieldDefaults: {
labelAlign: 'left',
msgTarget: 'none',
invalidCls: '' //unset the invalidCls so individual fields do not get styled as invalid
},
items: [{
xtype: 'toolbar',
items: [{
width: 280,
fieldLabel: 'Recherche',
id : 'psearch',
labelWidth: 60,
xtype: 'searchfield',
store: pstore
}, '->',{
xtype: 'component',
itemId: 'status',
tpl: 'R&eacute;sultat(s): {count}',
style: 'margin-right:5px'
}]
},{
xtype: 'grid',
store: pstore,
height: 470,
loadMask: true,
selModel: {
pruneRemoved: false
},
multiSelect: true,
listeners: {
selectionchange: function(selModel, selected) {
grid.down('#BAdd').setDisabled(false);
}
},
viewConfig: {
trackOver: false
},
// grid columns
columns:[{
// xtype: 'rownumberer',
text : "Abrev",
dataIndex: 'Abrev',
renderer: columnWrap,
width: 50,
sortable: true
},{
tdCls: 'x-grid-cell-topic',
text: "Lois et Ordonnances",
dataIndex: 'Title',
flex: 1,
renderer: columnWrap,
sortable: false
},{
text: "Art.",
dataIndex: 'Art',
align: 'center',
width: 50,
sortable: false
}],

dockedItems: [{
xtype: 'container',
dock: 'bottom',
padding: '10 10 5 105',

items: [{
xtype: 'button',
disabled: true,
id: 'BAdd',
text: 'Ajouter &agrave; ma biblioth&egrave;que',
width: 160,
handler: function() {
var form = this.up('form').getForm();

}
}] }]


}]
});

mitchellsimoens
22 Dec 2012, 8:38 AM
You could just use a convert function in the model field to remove special characters.