PDA

View Full Version : Ctrl + A functionality in grid too slow and issue with scroll bar.



jvarma80
10 Sep 2014, 1:08 PM
Hello all,

I have a results grid, say with 300 records. I am using the following code to select all the records in the grid when a user clicks ctrl + a in the grid.

{
key: Ext.EventObject.A,
ctrl: true,
fn: Ext.bind(this.doSelectAll, this)
defaultEventAction: "preventDefault"
}
doSelectAll: function(keyCode, event) {
var grid = this.view;
event.preventDefault();
grid.getSelectionModel().selectAll();
grid.getView().focusRow(0);
}
This code is doing what it is supposed to do, selecting all the records in the grid but it is taking too long to select the records. When I have some 10 records in the grid, then everything looks fine but when I am having some 300 records, it is taking almost 8-10 seconds to highlight all the records. If I select the first record in the grid, then type ctrl + A, the scroll bar keeps on going till the last record to highlight all the records. And I want the focus to be on the first record, so I am using the grid.getView().focusRow(0); statement which makes the scrollbar to come all the way up and this is again taking a long time. So the total ctrl-A functionality is taking something like 15-20 seconds to select all the records in the grid when there are more number of records and if I have some 1000 records, it may take forever.

Is there a better way of implementing this functionality?. I want all the records to be highlighted immediately after I press ctrl - A and also the focus should come back to the last selected record before I press ctrl-A.

Can you please suggest a better way of implementing this?.

Thanks.....

jvarma80
11 Sep 2014, 12:30 PM
I made the following change to the doSelectAll() function and it seems to be working little better in Firefox but having the same issue in IE. While selecting all the records, it goes till the end of the records and then again comes back to the first record. Is there a way to prevent this scrolling while it selects all the records when a user enters ctrl + a.

doSelectAll: function(keyCode, event) {
var grid = this.view;
event.preventDefault();
grid.getSelectionModel().selectAll();
setTimeout(function() {
grid.getView().scrollBy(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,false);
}, 0.0);
grid.getView().focusRow(0);
},