PDA

View Full Version : How to manually create filter with atributes like type and operation



hudi1
22 May 2013, 6:17 AM
Hi,

I examine this example. When I want to filter items by date it create request payload like this:



"data":[{"filter":"[{\"type\":\"date\",\"comparison\":\"lt\",\"value\":\"05/22/2013\",\"field\":\"date\"}]"




I dont want this feature in grid. I want separated form where I can set atrbite and when push button search it filter grid so I create this:






var gender = Ext.getCmp("gender").getValue()
if (gender == null) {
gender = ''
}
var dateOfBirthFrom = Ext.getCmp("dateOfBirthFrom").getValue()
if (dateOfBirthFrom == null) {
dateOfBirthFrom = ''
}
var dateOfBirthTo = Ext.getCmp("dateOfBirthTo").getValue()
if (dateOfBirthTo == null) {
dateOfBirthTo = ''
}




store.filter([Ext.create('Ext.util.Filter', {
property : "firstName",
value : Ext.getCmp("firstName").getValue()
}), Ext.create('Ext.util.Filter', {
property : "lastName",
value : Ext.getCmp("lastName").getValue()
}), Ext.create('Ext.util.Filter', {
property : "gender",
value : gender
}), Ext.create('Ext.util.Filter', {
property : "ssn",
value : Ext.getCmp("ssn").getValue()
}), Ext.create('Ext.util.Filter', {
property : "dateOfBirth",
value : dateOfBirthFrom,
type : 'date',
operator : "<"
})]);


this works good when filtering just string. It has problem to filter date because request payload look like:



filter":[{"property":"firstName","value":""},{"property":"lastName","value":""},{"property":"gender","value":""},{"property":"ssn","value":""},{"property":"dateOfBirth","value":""}]}



atributes like operator and type are missing. Why ? And how I can add it there ?

gentstr
22 May 2013, 9:58 AM
You can create your own encodeFilters in the proxy definition.



proxy: {
// Normal definition here

// Override proxy encodeFilters to append operator in remote filtering
encodeFilters: function(filters) {
var filtersOut = [];


for (var i = 0, l = filters.length; i < l; i++) {
filtersOut[i] = {
property: filters[i].property,
value: filters[i].value,
operator: filters[i].operator,
type: filters[i].type
};
}


return this.applyEncoding(filtersOut);
}
}

hudi1
23 May 2013, 1:49 AM
thx a lot it works