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;








3















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?.










share|improve this question


























  • 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

















3















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?.










share|improve this question


























  • 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













3












3








3


1






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?.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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










1 Answer
1






active

oldest

votes


















2














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++;






share|improve this answer



























  • Thanks! I missed the clear().

    – Milind Singh
    Jul 19 at 12:11














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
);



);













draft saved

draft discarded


















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









2














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++;






share|improve this answer



























  • Thanks! I missed the clear().

    – Milind Singh
    Jul 19 at 12:11
















2














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++;






share|improve this answer



























  • Thanks! I missed the clear().

    – Milind Singh
    Jul 19 at 12:11














2












2








2







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++;






share|improve this answer















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++;







share|improve this answer














share|improve this answer



share|improve this answer








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 the clear().

    – 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






Thanks! I missed the clear().

– Milind Singh
Jul 19 at 12:11


















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?