Bulk Operations don't work with DataTables as View display format.

When filtering (instant text search) or paginating the table you lose the previously selected items (the operation will act on the last selected item only).

I guess it's a javascript conflict but I'm not a developer :(

Comments

kopeboy created an issue. See original summary.

JacobCF’s picture

I am facing the same issue on Drupal 8. I can select multiple items, but all the items have to be on the same page.

dqd’s picture

Category: Bug report » Feature request
Status: Active » Closed (works as designed)

VBO and DT have different approaches to show table items. I think it should not be used together. I am even not sure if this can be implemented without a huge amount of patches on both sides: VBO and DT itself (not the Drupal module, which only manages the implementation). This is not a bug, rather a feature request. And consider it as possible unfullfilled dream.

dqd’s picture

Status: Closed (works as designed) » Closed (duplicate)

... and, BTW it's a duplicate of #1477850: VBO and DataTables

smulvih2’s picture

I just ran into this issue and was able to resolve by implementing a hidden checkbox to capture the selections from datatables.

Add hidden checkbox to VBO form using all values from $form['views_bulk_operations']:

function hook_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
  if ($form_state['step'] == 'views_form_views_form') {
    $options = array();

    foreach ($form['views_bulk_operations'] as $key => $value) {
      if (!empty($value['#type']) && $value['#type'] == 'checkbox') {
        $options[$value['#return_value']] = $key;
      }
    }

    $form['vbo_datatables_selection'] = array(
      '#title' => t('VBO Selections'),
      '#type' => 'checkboxes',
      '#description' => t('A placeholder checkbox field to hold selected VBO items.'),
      '#options' => $options,
      '#prefix' => '<div class="hide">',
      '#suffix' => '</div>',
    );
  }
}

Then in the form definition for a given operation I added the following to take the checkbox values and add to $form_state['selection'] so VBO has the values:

$lookup = $form_state['complete form']['vbo_datatables_selection']['#options'];

foreach ($form_state['values']['vbo_datatables_selection'] as $key => $value) {
  if ($value > 0) {
    $form_state['values']['views_bulk_operations'][$lookup[$key]] = $value;
    $form_state['selection'][$lookup[$key]] = $value;
  }
}

return $form_state;

From here VBO does the rest. I implemented this for D7, but I assume a similar technique could be used for D8.

dqd’s picture

@smulvih2 Thanks for your reports. But it is still a duplicate. Please report it in the first issue.