<p>Not that I'm aware of, but this feature request and response may at least help a bit. <a href="http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/7425151--expand-collapse-all-ui-for-matrix-fields" rel="nofollow">http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/7425151--expand-collapse-all-ui-for-matrix-fields</a></p>

CC BY-SA 3.0
2015-06-18T17:46:35.543Z
While its true that this doesn't come out of the box, it easily can be done.
Bob Olde Hampsink
CC BY-SA 3.0
2015-06-17T19:52:49.137Z
2015-06-17T19:52:49.137Z
Shift2Design
<p>Here's a simplified Craft CMS 5 version:</p>
<pre><code>(function($) { 

    // Function to collapse all matrix blocks
    function collapseAllMatrixBlocks() {
        $('.matrixblock').each(function() {
            var $block = $(this);
            var entry = $block.data('entry');
            
            // Only collapse if it's a valid matrix entry and not already collapsed
            if (entry &amp;&amp; !$block.hasClass('collapsed')) {
                entry.collapse();
            }
        });
    }

    // Add a small delay to ensure matrix blocks are fully initialized
    setTimeout(collapseAllMatrixBlocks, 200);

})(jQuery);
</code></pre>

CC BY-SA 4.0
2024-12-23T21:18:27.743Z
2024-12-23T21:18:27.743Z
Dario Zadro
<p>Inject this piece of JS in your CP and they will always be closed by default:</p>

<pre><code>$('.matrixblock').each(function() {
    $(this).addClass('collapsed');
    Craft.MatrixInput.rememberCollapsedBlockId($(this).data('id'));
});
</code></pre>

<p>Here's an example plugin that will inject it in the CP: <a href="https://gist.github.com/boboldehampsink/6bb9e5296977a99c39b1" rel="noreferrer">https://gist.github.com/boboldehampsink/6bb9e5296977a99c39b1</a></p>

CC BY-SA 3.0
2015-06-18T15:22:53.113Z
Great to hear!  What file do I add that code into?
Lori
CC BY-SA 3.0
2015-06-18T16:57:52.300Z
Its best to create a new plugin for it and make the `init()` function include the js. I've created a gist that should set you up: https://gist.github.com/boboldehampsink/6bb9e5296977a99c39b1
Bob Olde Hampsink
CC BY-SA 3.0
2015-06-18T20:44:26.700Z
Or you could just use [CP JS](https://github.com/lindseydiloreto/craft-cpjs) ;)
Lindsey D
CC BY-SA 3.0
2018-04-20T16:17:38.200Z
I can't get this working with CP JS in Craft 2 — the class is being appended but the field is still open... looks like the style needs to be changed too?

[EDIT: maybe it's because the matrix field is inside a Supertable?]
James Greig
CC BY-SA 4.0
2018-09-17T14:32:01.703Z
This would be handy to have just as a setting in the fieldtype.
Andy
CC BY-SA 4.0
2021-02-03T17:00:05.683Z
This used to work great. But does not seem to work in Craft 3.5. Any tips for updating?
Alex Kendrick
CC BY-SA 3.0
2015-06-18T11:55:40.093Z
2015-06-18T16:58:14.343Z
2015-06-18T16:58:14.343Z
Bob Olde Hampsink
<p>Is it possible to have all Matrix rows in the Control Panel entry be in the collapsed state by default?</p>

<p>Thanks.
Lori</p>

<matrix><control-panel>
Possible have matrix rows collapsed by default in the Control Panel?
# Possible have matrix rows collapsed by default in the Control Panel?

(Asked by: username_0 on 2015-06-17)

Is it possible to have all Matrix rows in the Control Panel entry be in the collapsed state by default?

Thanks.
username_0

**Tags:** matrix, control-panel


---

## 3 answers

### Answer by username_2 on 2015-06-18. Score: 10 | Accepted answer

Inject this piece of JS in your CP and they will always be closed by default:
$('.matrixblock').each(function() {
    $(this).addClass('collapsed');
    Craft.MatrixInput.rememberCollapsedBlockId($(this).data('id'));
});

Here's an example plugin that will inject it in the CP: https://gist.github.com/boboldehampsink/6bb9e5296977a99c39b1

> **Comments:**
> **username_0**: Great to hear!  What file do I add that code into?  
> **username_2**: Its best to create a new plugin for it and make the `init()` function include the js. I've created a gist that should set you up: https://gist.github.com/boboldehampsink/6bb9e5296977a99c39b1  
> **username_4**: Or you could just use [CP JS](https://github.com/lindseydiloreto/craft-cpjs) ;)  
> **username_5**: I can't get this working with CP JS in Craft 2 — the class is being appended but the field is still open... looks like the style needs to be changed too?  [EDIT: maybe it's because the matrix field is inside a Supertable?]  
> **username_6**: This would be handy to have just as a setting in the fieldtype.  
> **username_7**: This used to work great. But does not seem to work in Craft 3.5. Any tips for updating?  

---

### Answer by username_1 on 2015-06-17. Score: 2

Not that I'm aware of, but this feature request and response may at least help a bit. <http://feedback.buildwithcraft.com/forums/285221-feature-requests/suggestions/7425151--expand-collapse-all-ui-for-matrix-fields>

> **Comments:**
> **username_2**: While its true that this doesn't come out of the box, it easily can be done.  

---

### Answer by username_3 on 2024-12-23. Score: 0

Here's a simplified Craft CMS 5 version:
(function($) { 

    // Function to collapse all matrix blocks
    function collapseAllMatrixBlocks() {
        $('.matrixblock').each(function() {
            var $block = $(this);
            var entry = $block.data('entry');
            
            // Only collapse if it's a valid matrix entry and not already collapsed
            if (entry && !$block.hasClass('collapsed')) {
                entry.collapse();
            }
        });
    }

    // Add a small delay to ensure matrix blocks are fully initialized
    setTimeout(collapseAllMatrixBlocks, 200);

})(jQuery);


---

