Block/Adminhtml/Category/Grid.php
protected function _afterLoadCollection()
    {
        $categories = $this->categoryCollectionFactory->create()
            ->addAttributeToSelect('name')
            ->toOptionArray();

        $collection = clone $this->getCollection();
        $ordered = $this->getCollection()->removeAllItems();
        foreach ($categories as $category) {
            if ($item = $collection->getItemById($category['value'])) {
                $ordered->addItem($item);
            }
        }

        $this->setCollection($ordered);
        return parent::_afterLoadCollection();
    }
protected function _afterLoadCollection()
    {
        $categories = $this->categoryCollectionFactory->create()
            ->addAttributeToSelect('name')
            ->toOptionArray();

        $collection = clone $this->getCollection();
        $ordered = $this->getCollection()->removeAllItems();
        foreach ($categories as $category) {
            if ($item = $collection->getItemById($category['value'])) {
                $ordered->addItem($item);
            }
        }

        $this->setCollection($ordered);
        return parent::_afterLoadCollection();
    }
protected function _afterLoadCollection ( ) { $ categories = $ this -> categoryCollectionFactory -> create ( ) -> addAttributeToSelect ( 'name' ) -> toOptionArray ( ) ; $ collection = clone $ this -> getCollection ( ) ; $ ordered = $ this -> getCollection ( ) -> removeAllItems ( ) ; foreach ( $ categories as $ category ) { if ( $ item = $ collection -> getItemById ( $ category [ 'value' ] ) ) { $ ordered -> addItem ( $ item ) ; } } $ this -> setCollection ( $ ordered ) ; return parent :: _afterLoadCollection ( ) ; }
Sort category tree

{@inheritdoc}
Sort category tree