Magento 2: How to load data by Page using same collection object again?Magento 2: Why does a UI Listing Component need Two Collections?Least convoluted way of putting payment method objects in collectionMagento 2 get out of stock products in collectionMagento 2 Ui Component FormMagento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methodsHow does the CMS page admin form data provider gets its data?How to fully load customers when returned in a customer collection?Magento 2: Plugin class does not existMagento 2.2.3 :: How to check if ProductCollection exists?Magento2.2.4 : Uninstall a theme throw exceptions?
My employer is refusing to give me the pay that was advertised after an internal job move
May a hotel provide accommodation for fewer people than booked?
How does Asimov's second law deal with contradictory orders from different people?
"DDoouubbllee ssppeeaakk!!"
Can machine learning learn a function like finding maximum from a list?
Scam? Checks via Email
Why would anyone ever invest in a cash-only etf?
Was Donald Trump at ground zero helping out on 9-11?
Boots or trail runners with reference to blisters?
How to have poached eggs in "sphere form"?
Is there any way to work simultaneously on the same DAW project remotely?
Can a US President, after impeachment and removal, be re-elected or re-appointed?
Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here
Was the Psych theme song written for the show?
Solve equation using Mathematica
Should students have access to past exams or an exam bank?
What force enables us to walk? Friction or normal reaction?
Raindrops in Python
How do I make my photos have more impact?
What is this kind of symbol meant to be?
Antonym of "Megalomania"
Circle symbol compatible with square and triangle
Why does one get the wrong value when printing counters together?
Is it okay for me to decline a project on ethical grounds?
Magento 2: How to load data by Page using same collection object again?
Magento 2: Why does a UI Listing Component need Two Collections?Least convoluted way of putting payment method objects in collectionMagento 2 get out of stock products in collectionMagento 2 Ui Component FormMagento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methodsHow does the CMS page admin form data provider gets its data?How to fully load customers when returned in a customer collection?Magento 2: Plugin class does not existMagento 2.2.3 :: How to check if ProductCollection exists?Magento2.2.4 : Uninstall a theme throw exceptions?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am using MagentoCatalogModelResourceModelProductCollectionFactory
and loading data by creating objects.
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$result = $collection->getData();
The $result
contains the first-page result. Can I use the same object to render the second-page result?.
magento2 collection
add a comment |
I am using MagentoCatalogModelResourceModelProductCollectionFactory
and loading data by creating objects.
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$result = $collection->getData();
The $result
contains the first-page result. Can I use the same object to render the second-page result?.
magento2 collection
change setCurPage(1) to setCurPage(2) and check what results you are getting..
– aravind
Jul 19 at 12:06
It returns the previous data.
– Milind Singh
Jul 19 at 12:08
add a comment |
I am using MagentoCatalogModelResourceModelProductCollectionFactory
and loading data by creating objects.
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$result = $collection->getData();
The $result
contains the first-page result. Can I use the same object to render the second-page result?.
magento2 collection
I am using MagentoCatalogModelResourceModelProductCollectionFactory
and loading data by creating objects.
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$result = $collection->getData();
The $result
contains the first-page result. Can I use the same object to render the second-page result?.
magento2 collection
magento2 collection
edited Jul 21 at 14:52
Milind Singh
asked Jul 19 at 12:01
Milind SinghMilind Singh
8462 silver badges15 bronze badges
8462 silver badges15 bronze badges
change setCurPage(1) to setCurPage(2) and check what results you are getting..
– aravind
Jul 19 at 12:06
It returns the previous data.
– Milind Singh
Jul 19 at 12:08
add a comment |
change setCurPage(1) to setCurPage(2) and check what results you are getting..
– aravind
Jul 19 at 12:06
It returns the previous data.
– Milind Singh
Jul 19 at 12:08
change setCurPage(1) to setCurPage(2) and check what results you are getting..
– aravind
Jul 19 at 12:06
change setCurPage(1) to setCurPage(2) and check what results you are getting..
– aravind
Jul 19 at 12:06
It returns the previous data.
– Milind Singh
Jul 19 at 12:08
It returns the previous data.
– Milind Singh
Jul 19 at 12:08
add a comment |
1 Answer
1
active
oldest
votes
The collection data can be reset by using clear
function in $collection
and then changing the page will provide next page data.
The following code might be helpful.
$limit = 10;
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$pages = $collection->getLastPageNumber();
$page = 1;
while ($page <= $pages)
$collection->clear();
$collection->setCurPage($page);
$result = $collection->getData();
$page++;
Thanks! I missed theclear()
.
– Milind Singh
Jul 19 at 12:11
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282649%2fmagento-2-how-to-load-data-by-page-using-same-collection-object-again%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The collection data can be reset by using clear
function in $collection
and then changing the page will provide next page data.
The following code might be helpful.
$limit = 10;
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$pages = $collection->getLastPageNumber();
$page = 1;
while ($page <= $pages)
$collection->clear();
$collection->setCurPage($page);
$result = $collection->getData();
$page++;
Thanks! I missed theclear()
.
– Milind Singh
Jul 19 at 12:11
add a comment |
The collection data can be reset by using clear
function in $collection
and then changing the page will provide next page data.
The following code might be helpful.
$limit = 10;
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$pages = $collection->getLastPageNumber();
$page = 1;
while ($page <= $pages)
$collection->clear();
$collection->setCurPage($page);
$result = $collection->getData();
$page++;
Thanks! I missed theclear()
.
– Milind Singh
Jul 19 at 12:11
add a comment |
The collection data can be reset by using clear
function in $collection
and then changing the page will provide next page data.
The following code might be helpful.
$limit = 10;
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$pages = $collection->getLastPageNumber();
$page = 1;
while ($page <= $pages)
$collection->clear();
$collection->setCurPage($page);
$result = $collection->getData();
$page++;
The collection data can be reset by using clear
function in $collection
and then changing the page will provide next page data.
The following code might be helpful.
$limit = 10;
$collection = $this->collectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('simple', 'configurable'))
->setPageSize($limit)
->setCurPage(1);
$pages = $collection->getLastPageNumber();
$page = 1;
while ($page <= $pages)
$collection->clear();
$collection->setCurPage($page);
$result = $collection->getData();
$page++;
edited Jul 19 at 12:21
Milind Singh
8462 silver badges15 bronze badges
8462 silver badges15 bronze badges
answered Jul 19 at 12:10
Anjali RaiAnjali Rai
362 bronze badges
362 bronze badges
Thanks! I missed theclear()
.
– Milind Singh
Jul 19 at 12:11
add a comment |
Thanks! I missed theclear()
.
– Milind Singh
Jul 19 at 12:11
Thanks! I missed the
clear()
.– Milind Singh
Jul 19 at 12:11
Thanks! I missed the
clear()
.– Milind Singh
Jul 19 at 12:11
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282649%2fmagento-2-how-to-load-data-by-page-using-same-collection-object-again%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
change setCurPage(1) to setCurPage(2) and check what results you are getting..
– aravind
Jul 19 at 12:06
It returns the previous data.
– Milind Singh
Jul 19 at 12:08