Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been developing a plugin where I wanted to create a table, styled and working just like Wordpress's native Post/Page tables.

Following the guide below, I was able to create the table and load my database. The only thing I cannot figure out to do is how to make one of the row contents "clickable".

http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/

IE - making the "name" column clickable. I have the "edit, delete" buttons below the name, but that is not enough.

Any and all advice would be greatly appreciated. I looked at another plugin to see how they did this, and it looked like they broke the table apart and hardcoded the html for the table. I hope I don't have to do this.

EDIT:

clickable, linked, name

The name of the post, Hello world!, as you can see, is a link / clickable.

SOLUTION

to make this work, I had to remove my custom column functions, which included my row actions. Turns out, you can simply call the row actions div! Here is the function that helped me, thanks to the Milo.

function single_row_columns($item) {
       list($columns, $hidden) = $this->get_column_info();
            foreach ($columns as $column_name => $column_display_name) {
                   $class = "class='$column_name column-$column_name'";

                   $style = '';
                   if (in_array($column_name, $hidden))
                         $style = ' style="display:none;"';

                   $attributes = "$class$style";

                   if ('cb' == $column_name) {
                   echo  "<td $attributes>";
                   echo '<input type="checkbox" name="id[]" value="%s" />', $item['ID'];
                   echo "</td>";
                        }
               elseif ('galname' == $column_name) {
               echo "<td $attributes>";
               echo '<a href="#">', $item['galname'];
               echo "</a>";

                   echo "<div class='row-actions'><span class='edit'>";
           echo sprintf('<a href="?page=%s&action=%s&gid=%s">Edit</a>',$_REQUEST['page'],'edit',$item['id']);
                   echo "</span> | <span class='trash'>";
           echo sprintf('<a href="?page=%s&action=%s&gid=%s">Delete</a>',$_REQUEST['page'],'delete',$item['id']);
           echo "</span></div></td>";
                                                    }
            else {
                echo "<td $attributes>";
                echo $this->column_default( $item, $column_name );
                echo "</td>";
            } } } 

Thanks so much! Jacob

share|improve this question
    
The tutorial you linked tells you how to do it under "Sorting". –  Milo Jan 26 '13 at 18:55
    
Maybe you're seeing something I'm not, but I didn't find anything that said how to do that. I intend to make Hello World clickable, not the actual "title". My wording might have thrown that off. –  Jacob Raccuia Jan 26 '13 at 19:06
    
oh, I understand. what's supposed to happen when you click it? wrap it in an anchor tag. –  Milo Jan 26 '13 at 19:08
    
That's exactly what I want to do, but the current code I use to display my table doesn't include the functions required. –  Jacob Raccuia Jan 26 '13 at 20:49
add comment

2 Answers

up vote 0 down vote accepted

The WP_List_Table class ultimately uses the single_row_columns method to output each table cell. If we look at that method, we'll see this part:

...
elseif ( method_exists( $this, 'column_' . $column_name ) ) {
    echo "<td $attributes>";
    echo call_user_func( array( &$this, 'column_' . $column_name ), $item );
    echo "</td>";
}
...

Add a method to your class for the column you want to add additional functionality / formatting to and name it 'column_' . $column_name, then output any additional markup you need wrapping the item content.

share|improve this answer
    
I'm not sure how to incorporate this into my current display. I've added the "single_row_columns function. How do I call it? I'm going to edit my original post to include the code I use to display the results. –  Jacob Raccuia Jan 26 '13 at 20:45
    
if your column is named title, add a function named column_title, the display method will call that function when outputting the text for the title column, passing $item as an argument to that function. –  Milo Jan 26 '13 at 23:13
    
Thank you! I ended up removing my individual class calls, and making my own row actions. –  Jacob Raccuia Jan 27 '13 at 9:46
add comment

If you mean the "Quick Edit" feature of the posts and comments tables: I'm working on a tutorial for this feature but it will take some time to find an easy understandable solution. As you might have guessed it's a mixture of PHP, jQuery and Ajax.

I've searched the Net for any hints on how to implement the feature but the only available example is the source of the WordPress core.

share|improve this answer
    
Nope, quick edit is not what I'm looking for. I'm editing my answer to include a picture of what I mean. –  Jacob Raccuia Jan 26 '13 at 18:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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