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

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form