Create a draggable table and save weights I'm struggling a bit with creating a draggable table.

I want to have a table that lists node labels, where it's possible to rearrange the order of the nodes. The new weights shall be available when I submit the form.

This is my code so far:

$rows = [];
foreach ($nodes as $node) {
  $weight = $node-&gt;weight;

  $row = [
    'weight' =&gt; $weight,
    $node-&gt;label(),
  ];

  $rows[] = [
    'data' =&gt; $row,
    'class' =&gt; ['draggable'],
    '#weight' =&gt; $weight,
  ];

  $form['table'][$node-&gt;id()]['weight'] = [
    '#type' =&gt; 'weight',
    '#title' =&gt; t('Weight'),
    '#title_display' =&gt; 'invisible',
    '#default_value' =&gt; $weight,
    '#attributes' =&gt; [
      'class' =&gt; [
        'draggable-weight'
      ]
    ],
  ];
}

$form['table'] = [
  '#type' =&gt; 'table',
  '#header' =&gt; [
    $this-&gt;t('Weight'),
    $this-&gt;t('Title'),
  ],
  '#rows' =&gt; $rows,
  '#attributes' =&gt; [
    'id' =&gt; 'my-module-table'
  ],
  '#tabledrag' =&gt; [[
    'action' =&gt; 'order',
    'relationship' =&gt; 'sibling',
    'group' =&gt; 'draggable-weight',
  ]],
];


When I kint($form_state-&gt;getValues()) in my submit handler table is equals to ''.

I feel like I'm missing something simple, but the lack of documentation for this makes it hard to find out.
With the help from @Leigh I found the problem. I was setting some keys on $form['table'][$node-&gt;id()] and then overriding $form['table'][$node-&gt;id()] at the bottom.

I have moved a bit around in the code and now it works perfectly.

$form['table'] = [
  '#type' =&gt; 'table',
  '#header' =&gt; [
    '',
    $this-&gt;t('Weight'),
    $this-&gt;t('Title'),
  ],
  '#attributes' =&gt; [
    'id' =&gt; 'my-module-table'
  ],
  '#tabledrag' =&gt; [[
    'action' =&gt; 'order',
    'relationship' =&gt; 'sibling',
    'group' =&gt; 'draggable-weight',
  ]],
];

foreach ($nodes as $node) {
  $weight = $node-&gt;weight;

  $form['table'][$node-&gt;id()] = [
    'data' =&gt; [],
  ];
  $form['table'][$node-&gt;id()]['#attributes']['class'] = ['draggable'];
  $form['table'][$node-&gt;id()]['weight'] = [
    '#type' =&gt; 'weight',
    '#title' =&gt; t('Weight'),
    '#title_display' =&gt; 'invisible',
    '#default_value' =&gt; $weight,
    '#attributes' =&gt; [
      'class' =&gt; [
        'draggable-weight'
      ]
    ],
  ];
  $form['table'][$node-&gt;id()]['label'] = [
    '#markup' =&gt; $node-&gt;label(),
  ];
}