0

How can I remove the checkbox from tableselect form header (Drupal 7) only? I am looking for any configuration if available that can be applied in the below sample code:

$form['listings'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No Listing available.'),
);
1

The checkbox on the header is the Check all one. As the documentation about the tableselect form element says, just set the #js_select property to FALSE. In your case, the code would become the following one.

$form['listings'] = array(
  '#type' => 'tableselect',
  '#js_select' => FALSE,
  '#header' => $header,
  '#options' => $options,
  '#empty' => t('No Listing available.'),
);

See also the code of theme_tableselect(), the theme function responsible of rendering tableselect elements.

// Add an empty header or a "Select all" checkbox to provide room for the
// checkboxes/radios in the first table column.
if ($element['#js_select']) {

  // Add a "Select all" checkbox.
  drupal_add_js('misc/tableselect.js');
  array_unshift($header, array(
    'class' => array(
      'select-all',
    ),
  ));
}
else {

  // Add an empty header when radio buttons are displayed or a "Select all"
  // checkbox is not desired.
  array_unshift($header, '');
}
0

Better to use drupal table theme instead of tableselect.

  $header = array('Cell 1', 'Cell 2');
  $data = array( 
            array('A', 'B'),
            array('C', 'D')
  );
  $output = theme('table', 
           array('header' => $header, 
                  'rows' => $data ));
  return $output;

https://alvinalexander.com/drupal/drupal-theme-table-example-theme_table-function

  • A simple table doesn't show a checkbox for each table row. – kiamlaluno Feb 18 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.