Welcome Guest, Not a member yet? Register   Sign In
add css class to current row using HTML Table Class
#1

[eluser]kulldox[/eluser]
I have the following piece of code:
Code:
$data = $this->pages->pages(); // List the pages
        $this->table->set_heading(lang('title'), lang('slug'), lang('actions')); // Setting headings for the table

        $actions = '';
        foreach($data as $value => $key)
        {
            if( $key['status'] == '1') //if visible
            {
                $actions = anchor(prep_url(base_url())."pages/hide/".$key['id']."/", '<img src="'.prep_url(base_url()).'img/visible.png">', array('title' => (lang('hide').' '.lang('page')))); // Build actions links
            } else {
                $actions = anchor(prep_url(base_url())."pages/show/".$key['id']."/", '<img src="'.prep_url(base_url()).'img/hidden.png">', array('title' => (lang('show').' '.lang('page')))); // Build actions links
            }
            $actions .= ' ';
            $actions .= anchor(prep_url(base_url())."pages/edit/".$key['id']."/", '<img src="'.prep_url(base_url()).'img/edit.png">', array('title' => (lang('edit').' '.lang('page'))));
            $actions .= ' ';
            $actions .= anchor(prep_url(base_url())."pages/delete/".$key['id']."/", '<img src="'.prep_url(base_url()).'img/emptytrash.png">', array('title' => (lang('delete').' '.lang('page')))); // Build actions links
            
            $trClass = '<tr class="'.($key['status'] == '2' ? 'hidden' : '').'">';
            $tableTmpl = array (
                'row_start'  => $trClass,
                'row_alt_start' => $trClass
            );
            //var_dump($tableTmpl);
            $this->table->set_template($tableTmpl);        
            $this->table->add_row($key['title'], $key['slug'], $actions); // Adding row to table
        }

What I want to do i to set a the .hidden css class to the row that has:
Code:
$key['status'] = '2'
which stands for hidden.

The way I did it here actually sets the classes for whole table but not the current row.

How to do it for the current row using the HTML Table Class?

Shure I know how to do it with out HTML Table Class Big Grin
#2

[eluser]überfuzz[/eluser]
Why do you have to put it out if it's going to be hidden? *Just curios*
#3

[eluser]kulldox[/eluser]
[quote author="überfuzz" date="1251649104"]Why do you have to put it out if it's going to be hidden? *Just curios*[/quote]

The reason for that is I want to apply a different style (lets say to make the text Grey) to the row that is hidden, so it differ from the rest.

It's a show/hide function for front end pages Smile
#4

[eluser]überfuzz[/eluser]
Ok, in that case do you really have to make the array like that, if you just gonna alter it?

How does the array look and where is it rendered?
#5

[eluser]kulldox[/eluser]
#überfuzz, what do you mean "...do you really have to make the array like that, if you just gonna alter it?".

The array is:
Code:
array(3) {
  [0]=>
  array(9) {
    ["id"]=>
    string(1) "6"
    ["title"]=>
    string(4) "home"
    ["content"]=>
    string(3318) "Lorem ipsum dolo..."
    ["slug"]=>
    string(4) "home"
    ["status"]=>
    string(1) "1"
    ["created"]=>
    string(19) "0000-00-00 00:00:00"
    ["author"]=>
    string(1) "1"
    ["updated"]=>
    string(19) "0000-00-00 00:00:00"
    ["updater"]=>
    string(1) "0"
  }
  [1]=>
  array(9) {
    ["id"]=>
    string(1) "8"
    ["title"]=>
    string(4) "Test"
    ["content"]=>
    string(16) "Just a test page"
    ["slug"]=>
    string(4) "test"
    ["status"]=>
    string(1) "1"
    ["created"]=>
    string(19) "0000-00-00 00:00:00"
    ["author"]=>
    string(1) "1"
    ["updated"]=>
    string(19) "0000-00-00 00:00:00"
    ["updater"]=>
    string(1) "0"
  }
  [2]=>
  array(9) {
    ["id"]=>
    string(1) "9"
    ["title"]=>
    string(5) "test2"
    ["content"]=>
    string(1308) "&lt;img width=&quot;80&quot; height=&quot;80&quot; alt=&quot;&quot; src=&quot;/assets/image/avatar.jpeg&quot; /&gt;asdfsdf
"
    ["slug"]=>
    string(5) "test2"
    ["status"]=>
    string(1) "1"
    ["created"]=>
    string(19) "0000-00-00 00:00:00"
    ["author"]=>
    string(1) "1"
    ["updated"]=>
    string(19) "2009-08-29 09:05:02"
    ["updater"]=>
    string(1) "6"
  }
}
and is redered in the controller for now, but will move it to the view later as I think it should belong to it.

But that's not important.

In my opinion the $this->table->add_row() method should have the ability to pass additional parameter to the <tr> tag, like css, javascript or other stuff like that.

I'll see, or all extend the Table Helper or I'll use raw html for this.
#6

[eluser]überfuzz[/eluser]
Mhmm. I haven't used the function you're referring. I would fix it with a if-statement. The code below isn't fancy, but you'll definitively understand it.

Code:
if(!$data['active'])
{
   $some_css_class = "normal_css";
}
else
{
   $some_css_class = "special_css";
}

html_output .= "<tr class=\"".$some_css_class." etc </tr>";

Hope you get my point, hope I've understand your issue. ;-)
#7

[eluser]kulldox[/eluser]
[quote author="überfuzz" date="1251668523"]Mhmm. I haven't used the function you're referring. I would fix it with a if-statement. The code below isn't fancy, but you'll definitively understand it.

Code:
if(!$data['active'])
{
   $some_css_class = "normal_css";
}
else
{
   $some_css_class = "special_css";
}

html_output .= "<tr class=\"".$some_css_class." etc </tr>";

Hope you get my point, hope I've understand your issue. ;-)[/quote]

As I said previously, I know how to do it with raw HTML Big Grin. My question is how to do it with the Table Helper.
#8

[eluser]InsiteFX[/eluser]
Hi,

It's a Library Class not a helper!

All you need to do is extend the library with your own and add the functions / methods that you need.

Enjoy
InsiteFX
#9

[eluser]kulldox[/eluser]
[quote author="InsiteFX" date="1251709591"]Hi,

It's a Library Class not a helper!

All you need to do is extend the library with your own and add the functions / methods that you need.

Enjoy
InsiteFX[/quote]

Yep, you're right... not a helper Smile

[quote author="InsiteFX" date="1251709591"]Hi,

... extend the library with your own and add the functions / methods that you need.

[/quote]
Anyway, that's what I was thinking about too.




Theme © iAndrew 2016 - Forum software by © MyBB