diff -u b/src/Element/Tablefield.php b/src/Element/Tablefield.php --- b/src/Element/Tablefield.php +++ b/src/Element/Tablefield.php @@ -101,6 +101,7 @@ 'class' => ['table-rows-weight'], ], ], + '#weight' => $weight, ]; $draggable = TRUE; @@ -137,7 +138,7 @@ // Sort rows by weight. This step is required so that the table stays // properly ordered when doing ajax operations. - uasort($weightedRows, ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']); + uasort($weightedRows, ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']); $element['tablefield']['table'] += $weightedRows; // To change number of rows. diff -u b/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php b/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php --- b/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php +++ b/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php @@ -152,7 +152,6 @@ // Run the table through input filters. foreach ($tabledata as $row_key => &$row) { - unset($row['weight']); foreach ($row as $col_key => $cell) { $tabledata[$row_key][$col_key] = [ 'data' => empty($table->format) ? $cell : check_markup($cell, $table->format), only in patch2: unchanged: --- a/src/Plugin/Field/FieldWidget/TablefieldWidget.php +++ b/src/Plugin/Field/FieldWidget/TablefieldWidget.php @@ -204,6 +204,20 @@ class TablefieldWidget extends WidgetBase implements ContainerFactoryPluginInter } } + /** + * {@inheritDoc} + */ + public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + foreach ($values as &$value) { + $rows = &$value['tablefield']['table']; + foreach ($rows as &$row) { + unset($row['weight']); + } + } + + return parent::massageFormValues($values, $form, $form_state); + } + /** * {@inheritdoc} *