PDA

View Full Version : How to open a link with as params all grid filters/sorters/groupers



Fire-Dragon-DoL
16 Sep 2012, 9:41 AM
I'm trying to open a link in a new page, but my basic problem is opening it using the same filters/sorters/groupers as the grid where the button is positioned to.

Grid has "filters" property which contains used filters, however I can't find a groupers and sorters property.

Also, those filters/groupers/sorters aren't placed on the store, so I can't fetch them.

Any help appreciated.

mitchellsimoens
19 Sep 2012, 11:29 AM
Taking a look at the sorters property of the store I see the mixed collection has items in it.

Using the array grid example and click on the price column header I get this output:

38799

Maybe I'm not understanding?

Fire-Dragon-DoL
19 Sep 2012, 11:53 AM
Taking a look at the sorters property of the store I see the mixed collection has items in it.

Using the array grid example and click on the price column header I get this output:

38799

Maybe I'm not understanding?

Sorry, I made this question some time ago and I solved by myself yesterday night, I'll post the answer in a while.

However yes I found that the store has sorters/groupers, while the filters are stored on the grid.
I built a method that allows me to create a query url with filter/group/sort as params and now it's working fine.

I hoped for a standard method but it's ok in this way too.

Fire-Dragon-DoL
19 Sep 2012, 2:11 PM
Ok this is how I solved this issue:

Method on a custom grid panel class



/**
* Create a query link for current grid that can be used for external linking
* @param {String} format Takes an optional format to temporary override the proxy format for rest stores
*/
getQueryLink: function(format) {
var filters = [];
var groupers, sorters;

this.filters.filters.each(function(item) {
if (item.active) {
Ext.Array.forEach(item.serialize(), function(item) {
filters.push(item);
});
}
});
this.store.getAllFilters().forEach(function(item) {
filters.push(item);
});
groupers = Fdd.util.Object.getObjectGroupers(this.store.groupers);
sorters = Fdd.util.Object.getObjectSorters(this.store.sorters);

var shouldRestoreFormat = false;
if (Ext.isDefined(this.store.getProxy().format) && Ext.isDefined(format)) {
var lastStoreFormat = this.store.getProxy().format;
this.store.getProxy().format = format;
shouldRestoreFormat = true;
}

var operation = Ext.create('Ext.data.Operation', {
action: 'read'
});
var request = this.store.getProxy().buildRequest(operation);
var urlQuery = Ext.urlAppend(
this.store.getProxy().buildUrl(request),
Ext.Object.toQueryString({
filter: Ext.JSON.encode(filters),
group: Ext.JSON.encode(groupers),
sort: Ext.JSON.encode(sorters)
}, true)
);

if (shouldRestoreFormat)
this.store.getProxy().format = lastStoreFormat;

return urlQuery;
}

Method for the button


var excelPrint = Ext.create('Ext.Action', {
cls: 'icon-excel',
handler: function() {
// FIXME: GetQueryLink do not add format when proxy is an ajax proxy
var linkQuery = me.getQueryLink('xlsx');
console.log(linkQuery);
this.setHref(linkQuery);
return true;
},
href: '/trips.xlsx'
});

setHref method for button


Ext.override(Ext.button.Button, {
/**
* Set the current href of the button, you'll need to reset params
* @param {String} newHref Href that will be used (required)
* @return {String} Returns newHref
*/
setHref: function(newHref) {
this.btnEl.set({
href: newHref
});

return newHref;
}
});