Hallo,

in the Drupal 7 version it was possible to drag table rows. Will this also be possible in the Drupal 8 version? See attached screenshots...

Thanks in advance!

Issue fork tablefield-3040358

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mot-K created an issue. See original summary.

lolandese’s picture

Version: 8.x-2.0-alpha1 » 8.x-2.x-dev
Related issues: +#2578261: insert new row in the middle or rearrange rows

The D8 port was created before the D7 feature request #2578261: insert new row in the middle or rearrange rows was solved. Making a one-way feature comparison, looking at what is in D8 that is also in D7, we can conclude that the 7.x-2.4 mostly reflects what is in the D8 version.

That means that most new features that are in 7.x-2.5 are not in the D8 version. The new "major" version 7.x-3.x, taken from 7.x-2.5, is a rewrite of a big part of the code, including the data structure. Ideally, a new D8 port based on that should be created (@TODO). That would then include also the "row drag" feature.

Feel free to contribute with feedback, testing or providing patches.

matroskeen’s picture

Status: Active » Needs review
StatusFileSize
new5.78 KB

Hello guys,
Here is a patch with tabledrag integration. It seems it works well for us but it would be great to receive some feedback.

Thanks!

matroskeen’s picture

StatusFileSize
new5.66 KB

Fixed some issues and made a clean-up.

lolandese’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies cleanly and works as expected.

martin@martin-XPS-13-9370 /var/www/html/beige.localhost/web/modules/contrib/tablefield (8.x-2.x=) $ git apply -v tablefield-tabledrag_support-3040358-4-D8.patchChecking patch src/Element/Tablefield.php...
Checking patch src/Plugin/Field/FieldFormatter/TablefieldFormatter.php...
Checking patch src/Plugin/Field/FieldType/TablefieldItem.php...
Applied patch src/Element/Tablefield.php cleanly.
Applied patch src/Plugin/Field/FieldFormatter/TablefieldFormatter.php cleanly.
Applied patch src/Plugin/Field/FieldType/TablefieldItem.php cleanly.

Both Code Sniffer Drupal and Code Sniffer Drupal Best Practice pass without any errors or warnings.

martin@martin-XPS-13-9370 /var/www/html/beige.localhost/web/modules/contrib $ drupalcs tablefield
martin@martin-XPS-13-9370 /var/www/html/beige.localhost/web/modules/contrib $ drupalcsp tablefield
martin@martin-XPS-13-9370 /var/www/html/beige.localhost/web/modules/contrib $

Let's give it a couple of weeks and commit if no objections arise.

Thanks for the patch.

colan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Element/Tablefield.php
@@ -68,15 +68,46 @@ class Tablefield extends FormElement {
+    for ($i = 0; $i < $rows_amount; $i++) {
...
+      for ($ii = 0; $ii < $cols_amount; $ii++) {

@@ -135,11 +170,11 @@ class Tablefield extends FormElement {
+          '#value' => $cols_amount,

@@ -153,14 +188,14 @@ class Tablefield extends FormElement {
+        '#default_value' => $cols_amount,

+++ b/src/Plugin/Field/FieldType/TablefieldItem.php
@@ -175,6 +175,11 @@ class TablefieldItem extends FieldItemBase {
+      // Decrement amount of cols if there is a weight column.

Can we use more descriptive variable naming for all of these? Longer names are cheap nowadays, and it makes the code more maintainable (e.g. easier to read and understand). There's no reason to still be using $i and $ii for variable names. (It should be $j instead of $ii anyway. ;)

So that would be something like $row_id, $column_id, $number_of_columns and Decrement amount of columns if there is a weight column ("cols" -> "columns") respectively.

We should also have one more person test it. I can't do it right now, but should be able to soon (if nobody gets a chance before I get to it).

lolandese’s picture

Status: Needs work » Reviewed & tested by the community

Can we use more descriptive variable naming for all of these?

Doing a search for " $i " in Drupal core it finds 656 matches across 296 files. I think that, at least, we shouldn't treat this as being a blocker.

lolandese’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new83.08 KB
new224.73 KB

Apart from #8 above that suggests disabling row drag for rows with a default value, as implemented for the D7 version, it appears that row order on existing table rows is being changed when entering Edit mode. Likely to do with wrong row weights. See screenshots below.

Screenshot

Screenshot

lolandese’s picture

The file used for testing has been imported on a test node before applying the patch. Rename it to non-utf8.csv.

drupalisedmanish’s picture

Do we have any updates on status of the issue fix mentioned in comment #9

lolandese’s picture

Not yet. Feel free to work on it.

s.abbott’s picture

Status: Needs work » Needs review
StatusFileSize
new4.63 KB

I have taken a stab at the issues raised in #8 and #9, as well as re-rolling the patch so it applies to 8.x-2.x-dev and cleaning up some unnecessary changes. I think that with this it should be ready to go.

Also the $ii variable mentioned in #6 was there before this patch, so changing it would introduce unnecessary noise. I think that changing it is a good idea, just not bundled in with other changes.

s.abbott’s picture

StatusFileSize
new4.61 KB
new576 bytes

I realized that I accidentally left a debug value printout in #13.

s.abbott’s picture

StatusFileSize
new5.37 KB
new1.93 KB

I made a couple more small tweaks:

  1. Remove the 'weight' column before saving instead of during rendering.
  2. Sort by the '#weight' property instead of the 'weight' key (was working kinda by accident before).
s.abbott’s picture

StatusFileSize
new4.62 KB
new540 bytes

I realized I left a slight change in that should have been removed when I got rid of the unset($row['weight']); in the last patch.

heyehren’s picture

StatusFileSize
new90.36 KB

There seems to be an issue with drag and drop when in use tablefields inside paragraphs.

When i drag the paragraph row it seems to also effect the tablefield rows as well. See attached image.

heyehren’s picture

Hi s.abbott. I have applied your patch 16 and it doesn't work for me. I can not see the drag arrows in front of each row.

heyehren’s picture

Sorry about the noise, actually i previously applied the patch the wrong way. Now it"s all working. Thanks heaps for this patch!

jay.dansand’s picture

StatusFileSize
new4.63 KB
new953 bytes

I found with the patch and current HEAD of 8.x-2.x, commit b2f13ec (same commit as 8.x-2.2 release), saving tables removed all values. For what it's worth, I'm using Tablefield on a Paragraph entity. Attached is a small tweak to the #16 patch that fixed it in my case - could anyone else comment on which patch (this or #16) works for them with 8.x-2.2?

Status: Needs review » Needs work

The last submitted patch, 20: 3040358-tabledrag-support-20.patch, failed testing. View results

heyehren’s picture

@jay.dansand, I have the same issue with patch #16. When i safe the table all content is deleted.
Now i have updated to 8.x-2.2 and can no longer apply patch #16 via composer.
But i applied your patch #20 manually and now drag and drop is working without deleting table content when saving. Thank you!

ducktape’s picture

Status: Needs work » Needs review
StatusFileSize
new4.75 KB
new776 bytes

This broke sorting for me, with dragging and weight dropdowns, because the new order was not reflected in the values.

Updated the patch from 20.

Status: Needs review » Needs work

The last submitted patch, 23: 3040358-tabledrag-support-23.patch, failed testing. View results

ducktape’s picture

Status: Needs work » Needs review
StatusFileSize
new4.75 KB

Fixed the sort function in previous patch.

Status: Needs review » Needs work

The last submitted patch, 25: 3040358-tabledrag-support-24.patch, failed testing. View results

ducktape’s picture

The change from #20 breaks testing, as the "value" index introduced in the values array is not present when installed on a fresh drupal, and thus also during testing.

However I also see this "value" index in my own project, not using Paragraphs, so I guess there might be interference from other contrib.

yovince’s picture

StatusFileSize
new4.74 KB

Thanks @ducktape , just made a bit change to fit my project.

barry_fisher’s picture

We tried the patch in #28 and this still appears to delete content on save. I haven't had time to investigate why, maybe I'll get a chance if we come back to this, but I wanted to flag this here in case anyone thought (as we did) that the patch in #28 was a fix from the problems described above. Nevertheless, thanks to everyone trying to progress this feature - it certainly will be useful once resolved.

rowanadev’s picture

I removed the massageFormValues function from this patch and it is working well for me.
Thank you for the patch!

juanolalla’s picture

Status: Needs work » Needs review
StatusFileSize
new3.86 KB
new699 bytes

Following @RowanADev suggestion and my own testing, I've removed massageFormValues from patch 24 and it's working well now for me. Uploading updated patch and interdiff.

juanolalla’s picture

StatusFileSize
new5.05 KB
new1.2 KB

This implementation in patch #32 is adding a new column to the table to keep the weight values, so as a consequence that column was being shown by the field formatter. I've fixed that in this new patch.

anthonygray47’s picture

#32 provides the expected result.

Side note: If anyone uses Gin as their admin theme, this patch broke the Tablefield form display. I had to overwrite the following style to return the form display back to its previous state.

.paragraphs-tabs-wrapper .field-multiple-table .draggable > td + td {width: 100%; }

with

.form-tablefield table td + td { width: auto; }

jayhuskins’s picture

#32 works for me. However, when using "show row weights" the weight options are always -10 to 10 and do not reflect the number of rows in the table.

guilherme-lima-almeida’s picture

StatusFileSize
new5.08 KB

Hi there @jayhuskins,

I added the delta in the weight render element to the number of rows in the tablefield.

Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new43.74 KB
new45.19 KB

#35 working fine as per #34.

Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned

guilherme-lima-almeida’s picture

Assigned: Unassigned » guilherme-lima-almeida
Status: Reviewed & tested by the community » Fixed

Committed 26d63be6 and pushed to 8.x-2.x-dev.

I'll create a new release in the future for this feature.

guilherme-lima-almeida’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.