If you use the 'Show the empty text in the table' option and there are no results for the view's query, when template_preprocess_views_view_table($vars) is run in template_preprocess_datatables_view(), it results in the following value for $vars['rows']:

Array
(
    [0] => Array
        (
            [0] => 
        )

)

This in turn causes DataTables to throw the error "DataTables warning (table id = 'datatable-1'): Requested unknown parameter '1' from the data source for row 0". This is the result of table rendering the following:

<tbody>
          <tr class="views-row-first views-row-last">
                  <td class="views-field views-field-">
                      </td>
              </tr>
      </tbody>

The $vars['rows'] array should be an empty array if there is no data to display.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

zifiniti’s picture

Patch attached.

samstamport’s picture

I am getting this error, but 'Show the empty text in the table' option is not checked. I have a table I'm using in a view for the Project Management (PM) module. I have projects without tasks and projects with tasks. Could this be a similar problem? Is there a fix?

Update: I installed the dev version of datatables and the problem went away.

zifiniti’s picture

Status: Active » Needs review
dqd’s picture

Status: Needs review » Closed (outdated)

We are on 7.x 2.x and D8 now 3 years later ... so I would say this issue can be closed for now and reopened with changed code version option if somebody wants to report and patch it for 2.x or D8, if still required.