Welcome Guest, Not a member yet? Register   Sign In
html table class change colums mod
#1

[eluser]Ajaxboy[/eluser]
the current html table class doesn't allow to modify entire colums, just cells, here is a modification that allows you to modify entire colunms (i needed it html class wasn't flexible enough )

http://ellislab.com/codeigniter/user-gui...table.html

(please note that column change will take priority over a cell/row change...

(any hopes my changes can make it to a next release ? Smile )

Code:
$tmpl = array ('table_open' => '<table id="tickets_list" class="tikets">',
  
                    'heading_row_start'   => '<tr>',
                    'heading_row_end'     => '</tr>',
                    'heading_cell_start'  => '<th>',
                    'heading_cell_end'    => '</th>',
     'col_1_start' => '<td>',
     'col_1_end' => '</td>',
     'col_2_start' => '<td>',
     'col_2_end' => '</td>',

                    'row_start'           => '<tr>',
                    'row_end'             => '</tr>',
                    'cell_start'          => '<td>',
                    'cell_end'            => '</td>',

                    'row_alt_start'       => '<tr>',
                    'row_alt_end'         => '</tr>',
                    'cell_alt_start'      => '<td>',
                    'cell_alt_end'        => '</td>'
  );

note that col_1_start, col_2_start are new, ( and you can add as many as there are columns ( col_3_start,col_4_start, etc)..

CI_Table class in system/libraries/Table.php function generate:

Code:
/**
  * Generate the table
  *
  * @access public
  * @param mixed
  * @return string
  */
function generate($table_data = NULL)
{
  // The table data can optionally be passed to this function
  // either as a database result object or an array
  if ( ! is_null($table_data))
  {
   if (is_object($table_data))
   {
    $this->_set_from_object($table_data);
   }
   elseif (is_array($table_data))
   {
    $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
    $this->_set_from_array($table_data, $set_heading);
   }
  }

  // Is there anything to display?  No?  Smite them!
  if (count($this->heading) == 0 AND count($this->rows) == 0)
  {
   return 'Undefined table data';
  }

  // Compile and validate the template date
  $this->_compile_template();

  // set a custom cell manipulation function to a locally scoped variable so its callable
  $function = $this->function;

  // Build the table!

  $out = $this->template['table_open'];
  $out .= $this->newline;

  // Add any caption here
  if ($this->caption)
  {
   $out .= $this->newline;
   $out .= '<caption>' . $this->caption . '</caption>';
   $out .= $this->newline;
  }

  // Is there a table heading to display?
  if (count($this->heading) > 0)
  {
   $out .= $this->template['thead_open'];
   $out .= $this->newline;
   $out .= $this->template['heading_row_start'];
   $out .= $this->newline;

   foreach ($this->heading as $heading)
   {
    $temp = $this->template['heading_cell_start'];

    foreach ($heading as $key => $val)
    {
     if ($key != 'data')
     {
      $temp = str_replace('<th', "<th $key='$val'", $temp);
     }
    }

    $out .= $temp;
    $out .= isset($heading['data']) ? $heading['data'] : '';
    $out .= $this->template['heading_cell_end'];
   }

   $out .= $this->template['heading_row_end'];
   $out .= $this->newline;
   $out .= $this->template['thead_close'];
   $out .= $this->newline;
  }

  // Build the table rows
  if (count($this->rows) > 0)
  {
   $out .= $this->template['tbody_open'];
   $out .= $this->newline;

   $i = 1;
   foreach ($this->rows as $row)
   {
    if ( ! is_array($row))
    {
     break;
    }

    // We use modulus to alternate the row colors
    $name = (fmod($i++, 2)) ? '' : 'alt_';

    $out .= $this->template['row_'.$name.'start'];
    $out .= $this->newline;

    $row_count = 0;
    
    foreach ($row as $cell)
    {
     $row_count++;
    
     if(isset($this->template['col_'.$row_count.'_start'])) {
      $temp = $this->template['col_'.$row_count.'_start'];
     } else {
      $temp = $this->template['cell_'.$name.'start'];
     }
     foreach ($cell as $key => $val)
     {
      if ($key != 'data')
      {
       $temp = str_replace('<td', "<td $key='$val'", $temp);
      }
     }

     $cell = isset($cell['data']) ? $cell['data'] : '';
     $out .= $temp;

     if ($cell === "" OR $cell === NULL)
     {
      $out .= $this->empty_cells;
     }
     else
     {
      if ($function !== FALSE && is_callable($function))
      {
       $out .= call_user_func($function, $cell);
      }
      else
      {
       $out .= $cell;
      }
     }

    
     if(isset($this->template['col_'.$row_count.'_end'])) {
      $out .= $this->template['col_'.$row_count.'_end'];
     } else  {
      $out .= $this->template['cell_'.$name.'end'];
     }
    }

    $out .= $this->template['row_'.$name.'end'];
    $out .= $this->newline;
   }

   $out .= $this->template['tbody_close'];
   $out .= $this->newline;
  }

  $out .= $this->template['table_close'];

  // Clear table class properties before generating the table
  $this->clear();

  return $out;
}




Theme © iAndrew 2016 - Forum software by © MyBB