I want to sort images by position, and I am using this code

public function getCollection() {
   $collection = $this->_mymoduleFactory->create()->addFieldToFilter('status', 1)->setOrder('position', 'ASC');
   return $collection;

it is working perfectly fine from 0-9. when i give position as 10 it is showing after 1 like 0,1,10,2 etc. How could I sort correctly like 0,1,2,3...,10,11 etc? Any help is appreciated..


This issue probably caused by you set position column in DB to varchar. Update it to int and try again.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.