Hy. Its a nice Modul! :-)

Would it be possible somehow the "td-tags" add a separate class?

for example:
<td class="row_10 col_0 myClass">text</td>

Or can i do it with preprocess code?

Any ideas or code-snipets?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bernsch’s picture

Issue summary: View changes

code

Bernsch’s picture

Issue summary: View changes

text change

Bernsch’s picture

Issue summary: View changes

edit text

Bernsch’s picture

Issue summary: View changes

text change

Bernsch’s picture

How can i add a separate class to "td tags"?
Who has proposed one solution? Thx

xcono’s picture

I think, there is only hardcode solution for widget:

In function tablefield_field_widget_form under "Render the form table" comment:

for ($ii = 0; $ii < $count_cols; $ii++) {
      $instance_default = isset($instance['default_value'][$delta]['tablefield']["cell_{$i}_{$ii}"]) ? $instance['default_value'][$delta]['tablefield']["cell_{$i}_{$ii}"] : array();
      if (!empty($instance_default) && !empty($field['settings']['lock_values']) && $arg0 != 'admin') {
        // The value still needs to be send on every load in order for the
        // table to be saved correctly.
        $element['tablefield']['cell_' . $i . '_' . $ii] = array(
          '#type' => 'value',
          '#value' => $instance_default,
        );
        // Display the default value, since it's not editable.
        $element['tablefield']['cell_' . $i . '_' . $ii . '_display'] = array(
          '#type' => 'item',
          '#title' => $instance_default,
          '#prefix' => '<td style="cell-' . $ii . '">',
          '#suffix' => '</td>',
        );
      }
      else {
        $cell_default = isset($default_value[$i][$ii]) ? $default_value[$i][$ii] : '';
        $element['tablefield']['cell_' . $i . '_' . $ii] = array(
          '#type' => 'textfield',
          '#maxlength' => 2048,
          '#size' => 0,
          '#attributes' => array(
            'id' => 'tablefield_' . $delta . '_cell_' . $i . '_' . $ii,
            'class' => array('tablefield-row-' . $i, 'tablefield-col-' . $ii),
            'style' => 'width:100%'
          ),
          '#default_value' => (empty($field_value)) ? $cell_default : $field_value,
          '#prefix' => '<td style="width:' . floor(100/$count_cols) . '%">',
          '#suffix' => '</td>',
        );
      }
    }

Also you can use js.

Bernsch’s picture

Title: custom class to "td"-tag » custom class or line-number to "tr"-tag

Thanx xcono for this info.

Sorry i made ​​a mistake. I would add a custom class to the "tr"-tags NOT to a "td"-tag.
In my table-nodes I would always lift the placement of my team.
The placement this is different from table(-node) to table(-node).
I would give my team one class to the tr-tag.

Some ideas how to implement this?

Bernsch’s picture

Status: Active » Needs review

Here is the solution via JS-Code:

// add custom class to table tr-tag which contains a specific text
  
Drupal.behaviors.add-class-to-tr-tag = {
    attach: function (context, settings) {
      $('.tablefield td', context).each(function() {
        var that = $(this);
        if (that.text() == 'my-text-in-the-table-row') {
          that.parent('tr').addClass('my-custom-class');
        }
      });
    }
  };

It works for me! Thanks to yannickoo!

Bernsch’s picture

Status: Needs review » Reviewed & tested by the community
Bernsch’s picture

Issue summary: View changes

text change

lolandese’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Active

The suggested code changes/additions should be supplied as a patch.

lolandese’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
lolandese’s picture

Category: Feature request » Support request
Status: Active » Fixed

I guess this was a support request instead and is solved by the answers given (#2 and #4).

lolandese’s picture

Category: Support request » Feature request
Status: Fixed » Needs review
FileSize
943 bytes

Requested is:

custom class or line-number to "tr"-tag

Attached patch takes care of adding a line-number class to the "tr"-tag resulting in the following output:

<table id="tablefield-0" class="tablefield  sticky-enabled tableheader-processed sticky-table">
  <caption></caption>
   <thead><tr class="row_0"><th class="row_0 col_0" scope="col">Row 0 Column 0</th><th class="row_0 col_1" scope="col">Row 0 Column 1</th> </tr></thead>
  <tbody>
   <tr class="odd row_1"><td class="row_1 col_0">Row 1 Column 0</td><td class="row_1 col_1">Row 1 Column 1</td> </tr>
   <tr class="even row_2"><td class="row_2 col_0">Row 2 Column 0</td><td class="row_2 col_1">Row 2 Column 1</td> </tr>
  </tbody>
</table>

Still wondering the use case for this as the current possible:

td.row_2 {
    background-color: red;
}

..has the same effect as the newly possible:

tr.row_2 {
    background-color: red; 
}

Once that is clear it can be considered to be merged.