Hi guys,
I have two grids (GridPanel) and I want to implement a functionality to copy all rows from
source grid to target grid. Here is a snippet of my code (destStore is JsonStore):
Code:
this.copyAllRows = function (srcGrid, destGrid, destStore) {
// select all rows from src grid
srcGrid.getSelectionModel().selectAll();
// records array contains all selected rows
var records = srcGrid.getSelectionModel().getSelections();
for (var i = 0; i < records.length; i++) { // iterate all records
var foundItem = this.recordExists(records[i].get('id'), destGrid);
if (!foundItem) {
destStore.add(records[i]);
}
}
srcGrid.getSelectionModel().clearSelections();
}
copyAllRows() calls the recordExists() which determines if a row already exists in
target grid. Here is its code:
Code:
this.recordExists = function (str, grid) {
grid.getSelectionModel().selectAll();
var records = grid.getSelectionModel().getSelections();
for (var i = 0; i < records.length; i++) {
if (str == records[i].get('id')) {
grid.getSelectionModel().clearSelections();
return true;
}
}
grid.getSelectionModel().clearSelections();
return false;
}
my problem is that the copy procedure is too slow. Initially I used the store.find(...)
method to determine if a row already exists. It was much faster, but find() was not
working properly. For example if target store contained 'id' with value '111' and I was
looking for id '1', find() returned 'true' and the row with id=1 was not copied.
Can anyone propose an alternative solution (if any). Thanks in advance!