1
Array
(
    [table] => Array
        (
            [#type] => tableselect
            [#header] => Array
                (
                    [field_name] => FIELD NAME
                    [field_type] => FIELD TYPE
                    [no_of_values] => NO OF VALUES
                    [display_fields] => DISPLAY FIELDS
                    [field_label] => FIELD LABEL
                    [required] => Required
                    [product_type] => Product Type
                )

            [#options] => Array
                (





            [field_colour_pro] => Array
                        (
                            [field_name] => field_colour_pro
                            [field_type] => 
                            [no_of_values] => 
                            [display_fields] => 1
                            [field_label] => color
                            [required] => 0
                            [product_type] => shirt
                        )

                    [field_description] => Array
                        (
                            [field_name] => field_description
                            [field_type] => 
                            [no_of_values] => 
                            [display_fields] => 1
                            [field_label] => description
                            [required] => 0
                            [product_type] => test_pro_v
                        )

                )

            [#multiple] => 1
        )

$header = array(
    'field_name' => t('FIELD NAME'),
    'field_type' => t('FIELD TYPE'),
    'no_of_values' => t('NO OF VALUES'),
    'display_fields' => t('DISPLAY FIELDS'),
    'field_label' => t('FIELD LABEL'),
    'required' => t('Required'),
    'product_type' => t('Product Type'),
  );

  $rows = array();
  foreach(commerce_product_types() as $product_type => $product_type_array){
    $field_info = field_info_instances('commerce_product',$product_type);
    foreach($field_info as $machine_name =>$field_details){
      $rows[$machine_name] = array(
        'field_name' => $machine_name,
        'field_type' => $field_details['type'],
        'no_of_values' => $field_details['cardinality'],
        'display_fields'=>1,
        'field_label' => $field_details['label'],
        'required' => $field_details['required'],
        'product_type'=> $product_type,
      );

    }
  }

  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#multiple' => TRUE,
  );

//  print_r($form);
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

return $form;

I tried to get the tableselect form #type into operation it does not work and gives empty row even when each row has values,I would like to help me find any silly mistake which I am making out here

Here is image of how the table select looks which is empty enter image description here

2

I copied your code from and commented the variables and/or functions you're using since I don't know what they are for and just replaced a simple array to loop through.

/**
 * Implements hook_menu().
 */
function leomod_menu() {
  $items['leoo'] = array(
    'title' => 'asd',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('leomod_asd_form'),
    'access callback' => TRUE,
  );
  return $items;
}

/**
 * Form.
 */
function leomod_asd_form($form, &$form_state) {
  $header = array(
    'field_name' => t('FIELD NAME'),
    'field_type' => t('FIELD TYPE'),
    'no_of_values' => t('NO OF VALUES'),
    'display_fields' => t('DISPLAY FIELDS'),
    'field_label' => t('FIELD LABEL'),
    'required' => t('Required'),
    'product_type' => t('Product Type'),
  );

  $rows = array();
  $tests = array('1', '2', '3');
  //foreach(commerce_product_types() as $product_type => $product_type_array){
  foreach($tests as $test) {
    // $field_info = field_info_instances('commerce_product',$product_type);
    //foreach($field_info as $machine_name =>$field_details){
      $rows[$test] = array(
        'field_name' => $test,
        'field_type' => $test,
        'no_of_values' => $test,
        'display_fields'=> $test,
        'field_label' => $test,
        'required' => $test,
        'product_type'=> $test,
      );
    //}
  }

  $form['table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#multiple' => TRUE,
  );

  //  print_r($form);
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );

  return $form;
}

Since your table structure is working, I suspect there is something wrong with these lines:

foreach(commerce_product_types() as $product_type => $product_type_array) {

and

$field_info = field_info_instances('commerce_product',$product_type);
foreach($field_info as $machine_name =>$field_details) {

Also make sure you:

  1. Flushed caches
  2. Show all errors while developing since you're dealing with functions there that may return some errors that aren't displayed
  3. Check the variables and functions if they return anything by using print_r() or Devel module's dsm().
0

Check that the function (presumably buildForm()) implements "FormStateInterface". Drupal will render a table w/o children if not done from within such a function. See: tableselect form doesn't work.

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.