I got stuck on this, basically what I need is a way to auto expand category tree node that contains a sub category node checked.
The entry point in the code is  js/extjs/ext-tree-checkbox.js and 'catalog/category/tree.phtml'
It is possible to a expand a node in with expand() js method and it is no difficult to expand all node but this slow down the page too much.
Update:
I have tested the following solution:
Change js/extjs/ext-tree-checkbox.js render method adding this:
var tree = n.getOwnerTree();
    if (tree){
        expandNodeIds =  tree.expandNodeIds.split(',');
        for (i in expandNodeIds) 
        {
            if (n.id == expandNodeIds[i])
                n.expand();
        }
    }
This solution works but It breaks ( it is not displayed anymore ) the tree for permission Role
I did a little bug fixing and refactoring and packaged @obscures answer into a small extension. Give it a try on GitHub: Kiwigrid_AutoExpandProductCategoryTree
Because:
 - Google sees this as a solution
My solution is in Php side, in class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Categories.
// start Added stuff
protected $_ubProductCategoriesParents;
public function getUbProductCategories()
{
    if (is_null($this->_ubProductCategoriesParents)) {
        $this->_ubProductCategoriesParents = array();
        $this->_ubProductCategoriesParents = array();
        foreach ($this->getCategoryIds() as $id) {
            $storeId = (int) $this->getRequest()->getParam('store');
            $path = Mage::getResourceModel('catalog/category')
                ->getAttributeRawValue($id, 'path', $storeId); // no model->load ever ever ever
            if (empty($path)) {
                $path = "";
            }
            $parentsIds = explode("/", $path);
            if (!(is_array($parentsIds) && count($parentsIds) > 0)) {
                $parentsIds = array();
            }
            $this->_ubProductCategoriesParents = array_unique(array_merge($this->_ubProductCategoriesParents, $parentsIds));
        }
        //Mage::log(print_r($this->_ubProductCategoriesParents, true));
    }
    return $this->_ubProductCategoriesParents;
}
// end Added stuff
// magento core function from class
protected function _getNodeJson($node, $level = 1)
{
    $item = parent::_getNodeJson($node, $level);
    if ($this->_isParentSelectedCategory($node)) {
        $item['expanded'] = true;
    }
    // added new if statement
    if (!(isset($item['expanded']) && $item['expanded'] == true) && array_search($node->getId(), $this->getUbProductCategories()) !== false) {
        $item['expanded'] = true;
    }
    if (in_array($node->getId(), $this->getCategoryIds())) {
        $item['checked'] = true;
    }
    if ($this->isReadonly()) {
        $item['disabled'] = true;
    }
    return $item;
}
Going now to have the above code in a rewrite class.
Thank you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With