PDA

View Full Version : How to avoid that an event executes its action



csanchezr85
30 Aug 2012, 4:46 AM
Hello,

basically, I want to "tell" to the event that it doesn't have to execute its action. I explain my example: I have a grid (ext.grid.Panel) and I've added the listener for the "sortchange" event. When user clicks on a column to sort it, obviously this event is fired.

But the problem is that I only want the column and direction parameters in order to call to an own function to sort the grid by these parameters and others. And the event first sorts by its criterion and after my function sorts again, creating an ugly effect. So I want that the event doesn't raise its order action.

How can I do this?

Thanks.

tvanzoelen
30 Aug 2012, 4:47 AM
e.stopEvent() ?

csanchezr85
30 Aug 2012, 10:39 PM
Thanks for your reply. I think that I must use something like this, tvanzoelen, but in the code:



//Control the sorter columns g.on('sortchange', function (container, column, dir, opts) {


if (_self.pagingBar != null) {
_self.pagingBar.sortColumn = column.dataIndex;
_self.pagingBar.sortDir = dir;


//Load data
_self.pagingBar.getData(_self.pagingBar);
}
});


in the 'sortchange' event I don't have the event ('e') parameter and if I include the instruction 'e.stopEvent();', the event gives me an error.

tvanzoelen
31 Aug 2012, 12:03 AM
You can set your sorter function on the Store



var store = Ext.create('Ext.data.Store', {
model: 'User',
sorters: [{
property: 'age',
direction: 'DESC'
}, {
property: 'firstName',
direction: 'ASC'
}],

filters: [{
property: 'firstName',
value: /Ed/
}]
});


In the case above the sorter is an object , but you couild also set your function there, then then will be the default sorter for the grid.

seel also: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.util.Sorter

csanchezr85
31 Aug 2012, 2:28 AM
I've proved this. I have added a sorter function but it's still reordering the grid. I only want the column and direction sort, and defining a sorter function in the store I only get access to the direction, but I donĀ“t know how to obtain the column.

But finally I've opted to make columns not sorteables and I've added the 'headerclick' to them. So when user clicks on a header I add the css class to it (to indicate the direction of the sort) and call to my function that sorts the records.

Thanks for your responses.