Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T17:46:35.543Z
Answers.Text: While its true that this doesn't come out of the box, it easily can be done.
Answers.UserDisplayName: Bob Olde Hampsink
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-17T19:52:49.137Z
Answers.LastActivityDate: 2015-06-17T19:52:49.137Z
Answers.UserDisplayName: Shift2Design
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-23T21:18:27.743Z
Answers.LastActivityDate: 2024-12-23T21:18:27.743Z
Answers.UserDisplayName: Dario Zadro
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T15:22:53.113Z
Answers.Text: Great to hear!  What file do I add that code into?
Answers.UserDisplayName: Lori
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T16:57:52.300Z
Answers.Text: 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
Answers.UserDisplayName: Bob Olde Hampsink
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T20:44:26.700Z
Answers.Text: Or you could just use [CP JS](https://github.com/lindseydiloreto/craft-cpjs) ;)
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-20T16:17:38.200Z
Answers.Text: 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?]
Answers.UserDisplayName: James Greig
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-17T14:32:01.703Z
Answers.Text: This would be handy to have just as a setting in the fieldtype.
Answers.UserDisplayName: Andy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T17:00:05.683Z
Answers.Text: This used to work great. But does not seem to work in Craft 3.5. Any tips for updating?
Answers.UserDisplayName: Alex Kendrick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T11:55:40.093Z
Answers.LastActivityDate: 2015-06-18T16:58:14.343Z
Answers.LastEditDate: 2015-06-18T16:58:14.343Z
Answers.UserDisplayName: Bob Olde Hampsink
Body: <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>
  
Tags: <matrix><control-panel>
Title: Possible have matrix rows collapsed by default in the Control Panel?
ThreadText: # 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/username_2/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/username_2/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);
  
  ```
  
  
  ---
  
  