Created
November 25, 2013 20:11
-
-
Save MihailoJoksimovic/7648004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onBeforePagingPageChanges: function(pagingToolbar) { | |
var grid = pagingToolbar.up('grid[itemId="articlesListGrid"]'); | |
this.storeSelectedGridRecords(grid); | |
}, | |
/** | |
* Saves list of articles that were selected in given Grid. | |
*/ | |
storeSelectedGridRecords: function(grid) { | |
var me = this; | |
// Get reference to Grid's store | |
var store = grid.getStore(); | |
// ... and get selection model ... | |
var selectionModel = grid.getSelectionModel(); | |
// ... and finally get list of selected records and store it inside controller | |
var selection = selectionModel.getSelection(); | |
var catalogId = store.catalog_id; | |
selection = selection || []; | |
// First I will remove selection from all articles that are found on current page. | |
// This way I know that articles that user de-selected won't be left as selected | |
// in our internal array. | |
store.each(function(article) { | |
var articleId = article.get('st_article_id'); | |
if (me.selectedArticlesList[catalogId] && me.selectedArticlesList[catalogId][articleId]) { | |
delete me.selectedArticlesList[catalogId][articleId]; | |
} | |
}); | |
Ext.each(selection, function(article) { | |
if (!me.selectedArticlesList[catalogId]) { | |
me.selectedArticlesList[catalogId] = {}; | |
} | |
var articleId = article.get('st_article_id'); | |
me.selectedArticlesList[catalogId][articleId] = article; | |
}); | |
}, | |
/** | |
* Fires when user changes the page and that page has been loaded. | |
*/ | |
onAfterPagingPageHasBeenChanged: function(pagingToolbar) { | |
var grid = pagingToolbar.up('grid[itemId="articlesListGrid"]'); | |
this.preselectAlreadySelectedRecords(grid); | |
}, | |
preselectAlreadySelectedRecords: function(grid) { | |
var me = this; | |
// Get reference to Grid's store | |
var store = grid.getStore(); | |
// ... and get selection model ... | |
var selectionModel = grid.getSelectionModel(); | |
var catalogId = store.catalog_id; | |
var recordsToPreselect = []; | |
store.each(function(article) { | |
var articleId = article.get('st_article_id'); | |
if (me.selectedArticlesList[catalogId] && me.selectedArticlesList[catalogId][articleId]) { | |
recordsToPreselect.push(article); | |
} | |
}); | |
selectionModel.select(recordsToPreselect); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment