⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Change background color of an entire tr row in list



Edwin K

Edwin K
  • profile picture
  • Member

Posted 15 January 2018 - 17:04 PM

Hi,

 

I'm new to codeigniter. It's a great tool. But I still have some troubles to customize CI to my project needs.

 

I would like to change the background color of only one row in the list table to obtain this:

 

[attachment=1278:crud2.PNG]

 

Idealy i would like to use the bootstrap <tr class="success">...</tr>

 

But any other mean will be great.

 

So i succeeded with a callback to change the text to a link <a href>, to change the text color to green only for the row id which is corresponding to the id selected elsewhere.

 

here is the code:

$crud->callback_column('name',array($this,'_callback_webpage_url'));

and:

public function _callback_webpage_url($value, $row)
	{
		if ($this->session->userdata('company_select')==$row->id)
		{
			return "<a href='".site_url('page/company_edit/edit/'.$row->id)."' style='color: green;'>$value</a>";
		}
		else
		{
			return "<a href='".site_url('page/company_edit/edit/'.$row->id)."'>$value</a>";
		}
	} 

But now, what can I do to change the entire row <tr> ?

 

 

 

Many thanks for your help!


Edwin K

Edwin K
  • profile picture
  • Member

Posted 27 February 2018 - 09:50 AM

Finaly I found a solution:

 

(solution for bootstrap only)

 

1- In the page controller: store the row id to be highlighted in $this->session->set_userdata(array('selected_id' => $id));

 

2- in the file assets\grocery_crud\themes\bootstrap\views\list_tbody.php add this code around line 29, after the :

<?php 
    //ADDED BY ME IN ORDER TO CHANGE BACKGROUND COLOR OF ENTIRE tr ROW DEPENDING ON A VALUE
    $CI =& get_instance();
    //get the selected_id which is stored in session user's data
    $selected_id = $CI->session->userdata($table_name.'_select');
?>

3- Than just after in this foreach($list as $num_row => $row) loop, replace the <tr> tag by this if and else.

<?php foreach($list as $num_row => $row){ ?>

    <?php //ADDED

        if ($row->primary_key_value == $selected_id) {
            echo '<tr class="success">';
            
        } else {
            echo "<tr>";
            
        }
        // ADD END
     ?>

So now, when the row id is equal to the one stored in session, the succes style will be applied on the entire row.

 

Of course I know i have hacked the crud view system, but i think it was the only way.

 

And it works fine when necessary!