View Full Version : How do you do a deep copy of an ext object?

17 Apr 2012, 11:45 AM
We have implemented a grid with paging and we want to print that grid. However, when we print we want to print the entire result set not just the page on the grid. I was able to accomplish most of this using the printing plugin that's floating around the forums here. However I've run into a problem. In order to print the entire data set I'm doing this.

var newStore = Ext.clone(grid.store);
newStore.pageSize = newStore.getTotalCount();
newStore.load(function (records, operation, success) { <all the printing magic in here>});

As I said, that does print the entire data set. However, changing pageSize on newStore is doing so on the original grid. This is obvious an issue with javascript being by reference instead of value. However, I thought the point of clone was to get around that. The documentation isn't specific if it's a deep copy or just top level. I know apply is just top level but it says so my assumption was clone wasn't since it didn't specifically say so.

In theory I could track the previous pageSize and just reset that then reload but that obviously has some implications like losing your current selection. I'm not sure if that is a deal breaker for us but I'd prefer to do it right to start with if possible.

I suppose there is possibly a better way to load the entire data set that I'm not aware of as well. But I think you will only get whatever is in the cache of the page you are on rather than the entire data set when you do something like grid.store.data.each...etc.

17 Apr 2012, 12:24 PM
Have always found to better to use a server solution such as iText or TCPDF for presenting grid data in report form. If this is not an option, perhaps someone else may have a better solution for printing direct from the grid.


17 Apr 2012, 12:35 PM
I lobbied for a similar solution to iText but at the current time they are just wanting a quick resolution for ext based grids.

17 Apr 2012, 1:14 PM
Gotta love those 'quick solutions' that take longer than the best solution ;)