Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-39030

html_writer::table() ignores html_table_row->attributes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 2.2.6, 2.4.3, 2.4.8, 2.5.4, 2.6.1
    • General, Libraries
    • MOODLE_22_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE

      Consider the following code:

      $table = new html_table();
      $table->head = array('Name', 'Actions');
       
      $row = new html_table_row(array('Item #1', 'Example'));
      $row->attributes['data-id'] = '1';
      $table->data[] = $row;
       
      $row = new html_table_row(array('Item #2', 'Example'));
      $row->attributes['data-id'] = '2';
      $row->attributes['data-parentid'] = '1';
      $table->data[] = $row;
       
      echo html_writer::table($table);
      

      Which yields the following markup; notice the missing data-* attributes:

      <table class="generaltable">
          <thead>
              <tr>
                  <th class="header c0" style="" scope="col">Name</th>
                  <th class="header c1 lastcol" style="" scope="col">Actions</th>
              </tr>
          </thead>
          <tbody>
              <tr class="r0">
                  <td class="cell c0" style="">Item #1</td>
                  <td class="cell c1 lastcol" style="">Example</td>
              </tr>
              <tr class="r1 lastrow">
                  <td class="cell c0" style="">Item #2</td>
                  <td class="cell c1 lastcol" style="">Example</td>
              </tr>
          </tbody>
      </table>
      

      With the patch applied, the output is correct:

      <table class="generaltable">
          <thead>
              <tr>
                  <th class="header c0" style="" scope="col">Name</th>
                  <th class="header c1 lastcol" style="" scope="col">Actions</th>
              </tr>
          </thead>
          <tbody>
              <tr class=" r0" data-id="1">
                  <td class="cell c0" style="">Item #1</td>
                  <td class="cell c1 lastcol" style="">Example</td>
              </tr>
              <tr class=" r1 lastrow" data-id="2" data-parentid="1">
                  <td class="cell c0" style="">Item #2</td>
                  <td class="cell c1 lastcol" style="">Example</td>
              </tr>
          </tbody>
      </table>
      

      I have only tested this against 2.2.x, but a quick check of the 2.4 source indicates that this issue would occur on newer releases too.

            moodle.com Moodle HQ
            lukecarrier Luke Carrier
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.