• Resolved bitkahuna

    (@bitkahuna)


    thought this might help someone. was really stymied as to how to detect a user clicking on a row. i’m sure there’s a jquery way but i still can’t get through how to add handlers/plug-ins since the wp plug-in does the ‘ready’ function and there’s only that custom parameters deal, but anyway, i digress.

    using the (thank you!) sample wordpress plugin to extend wp-table reloaded, i did the following in wp-table-reloaded-extensions.php:

    function wp_table_reloaded_hack_row( $row_class, $table_id, $row_idx ) {
    	// row class will normally be output like this:
    	// $row_class = " class=\"{$row_class}\"";
    	// if we insert js in the middle, it might work...
    	// $row_class = " class=\"{old $row_class appeneded with \" onclick="alert('foo')\"';
    
    //	$row_class .= ' \" onclick="alert(\'foo\')';
    	$row_class .= "\" onclick=\"window.location = '/your-link-here'";
        return $row_class;
    }
    
    add_filter( 'wp_table_reloaded_row_css_class', 'wp_table_reloaded_hack_row', 10, 3);

    it ‘cheats’ by adding the event handler in the row string when adding css classes. πŸ™‚

    http://wordpress.org/extend/plugins/wp-table-reloaded/

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    nice hack, thanks for sharing it! πŸ™‚

    Doing this in jQuery should not be hard though. You don’t really need to worry about the jQuery code in WP-Table Reloaded, you would just need to add your own code to the page footer.
    A simple way for that is the “HiFi” plugin, or you could use one of the other WP-Table Reloaded filter hooks (of which I don’t know the name right now).

    Regards,
    Tobias

    How do you choose which tabel and row it’s added to?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    from how I understand bitkahuana’s code, you have to do this manually in the function, by checking the variables $table_id and $row_idx for the desired values.
    A JS solution based on jQuery could use the available CSS selectors for this.

    Regards,
    Tobias

    It wont work for me, all the rows just get clickable.
    Can you please give an example with e.g. table id 1 and row 3?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    sure:

    function wp_table_reloaded_hack_row( $row_class, $table_id, $row_idx ) {
        if ( 1 != $table_id )
            return $row_class;
        if ( 3 != $row_idx )
            return $row_class;
    
        $row_class .= "\" onclick=\"window.location = '/your-link-here'";
        return $row_class;
    }
    add_filter( 'wp_table_reloaded_row_css_class', 'wp_table_reloaded_hack_row', 10, 3);

    Regards,
    Tobias

    Thread Starter bitkahuna

    (@bitkahuna)

    sorry, been unavailable to respond until now.
    Tobias, thanks for handling this!!!
    What I’d LOVE to see though is an example of how to do it with jQuery. I’m pretty js literate and have done some jQuery, but I can’t figure out what to add to add functionality like this to your plugin (hence the hack).

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, bitkahuana πŸ™‚

    In jQuery, you could simply use something like this (for table 1 and row 3 here):

    <script type="text/javascript">
    jQuery(document).ready(function($){
      $('.wp-table-reloaded-id-1 .row-3').click(function() {
        window.location = 'http://www.example.com/';
      });
    });
    </script>

    This just needs to be added to the page footer, e.g. with the HiFi plugin.

    (Note: I did not test this, but that’s the way it should work.)

    Regards,
    Tobias

    Mr. Noob here I’m afraid… but can you please post an example of how to make 2 or more rows clickable and both linking to different pages?

    Making all rows or a single row clickable works for me now, but 3 rows with 3 different links I can’t get the hang off.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    which of the row click solutions are you trying to use? Can you post the link to the pages/tables that you are experimenting with?

    Regards,
    Tobias

    Hi, thank you for your quick reply. My site is in Maintenance Mode as it has not been launched, so I can not link to it yet.

    I am trying to use bitkahuna’s code with your example edit for row 3.

    function wp_table_reloaded_hack_row( $row_class, $table_id, $row_idx ) {
        if ( 1 != $table_id )
            return $row_class;
        if ( 3 != $row_idx )
            return $row_class;
    
        $row_class .= "\" onclick=\"window.location = '/your-link-here'";
        return $row_class;
    }
    add_filter( 'wp_table_reloaded_row_css_class', 'wp_table_reloaded_hack_row', 10, 3);

    Now I would like to make each row clickable and linking to a different page. I’m sure it’s pretty basic, but like I said, I am an absolute beginner but would love to get this to work as I’ve always loved clickable rows πŸ™‚

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the details. Then just extend the code like this:

    function wp_table_reloaded_hack_row( $row_class, $table_id, $row_idx ) {
        if ( 1 != $table_id )
            return $row_class;
    
        if ( 3 == $row_idx )
          $row_class .= "\" onclick=\"window.location = '/your-link-for-row-3-here'";
        else if ( 4 == $row_idx )
          $row_class .= "\" onclick=\"window.location = '/your-link-for-row-4-here'";
        else if ( 7 == $row_idx )
          $row_class .= "\" onclick=\"window.location = '/your-link-for-row-7-here'";
    
        return $row_class;
    }
    add_filter( 'wp_table_reloaded_row_css_class', 'wp_table_reloaded_hack_row', 10, 3);

    Regards,
    Tobias

    Thats really great, thanks!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    awesome! Thanks for the confirmation, that this will work for you πŸ™‚

    Best wishes,
    Tobias

    Thread Starter bitkahuna

    (@bitkahuna)

    ha, glad i’m getting notifications still on this thread and seeing the hack still being put to use! your plug-in is really awesome.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yes, that’s definitely a nice feature πŸ™‚

    And thanks for the nice words about the plugin!

    Best wishes,
    Tobias

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Plugin: WP-Table Reloaded] how to add row click support’ is closed to new replies.