WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin : wp-table-reloaded] extensions - colspan_trigger (10 posts)

  1. lambethboy
    Member
    Posted 4 years ago #

    Hi Tobias,

    Thanks for making a fantastic plugin. I am extending it using the plugin hooks and this is working well for me.

    However, could you give me an example of using the colspan trigger? I'd like to be able to make certain cells in my table span all rows.

    This is all I could find in the documentation -

    wp_table_reloaded_colspan_trigger ( $this->colspan_trigger, $table['id'] ) (string)

    Thanks in advance,
    Bill.

  2. TobiasBg
    Member
    Posted 4 years ago #

    Hi Bill,

    thanks for your question!

    You don't need that plugin hook just to combine cells in a table.
    That is actually done on the "Edit" screen of the table.

    Instead of entering content as usual, you need to add certain trigger words into them. They are "#colspan#" and "#rowspan#" (without the ", but with the #). But instead of actually entering the manually, it is much easier to use the buttons "Add colspan" and "Add rowspan" under the table edit fields. After clicking them, you just need to click in to the cell that shall be connected to either its left or top neighbor. (There also are small (?) buttons that explain how to use them more detailed.)

    (BTW: That plugin hook you mentioned is actually designed to be used if someone wants to change the trigger word from "#colspan#" to something else. But this should never be needed, unless you really want to use "#colspan#" as the value of one of your cells, but I actually doubt that :-) )

    I hope this explanation helps understand the feature. If not, just let me know where you have trouble with.

    Best wishes,
    Tobias

  3. lambethboy
    Member
    Posted 4 years ago #

    Hi Tobias,

    Thanks for the help. Actually what I need to do, but failed to explain is to use the plugin to automatically add some spanned cells to a table. So this would be totally separate from what a user might enter via the wp-table-reloaded web panel.

    At the moment I am using the plugin extention via the wp_table_reloaded_cell_content hook to add some content to the table when the user adds one of my custom tags, but would like the cell to span several columns. Is this possible? If not I can work around it by post processing the whole table, but it would be neat to do it via a span I think.

    Thanks,
    Bill.

  4. TobiasBg
    Member
    Posted 4 years ago #

    Hi Bill,

    ok, that makes it more clear.

    I just had a quick look at the code again, to see where to hook in for your idea.
    And I come to the conclusion that using the "wp_table_reloaded_cell_content" hook actually is the correct place.

    Besides the content of the cell, it gets also passed the table ID and the row and column number.
    With that you should be able to determine if you want the row to be spanning all cells.
    Then, all your function needs to do is return "#colspan#" as the actual search for that value will then colspan that row.

    So, basically, your current function that is hooked to the filter just needs to return your own content for the first cell of the row. For all other cells in that row, it needs to return "#colspan#". Does that make sense?

    I don't see why this should not work for you, but just in case: Two other possibilities would be post processing as you mention it (which I don't really recommend), using the "wp_table_reloaded_post_output_table" hook, or filtering the table content upon loading (hook "wp_table_reloaded_post_load_table" (include a check for is_admin() in it!). That would give you the array of the table values where you could do your necessary content insertion, also using the "#colspan#" words in the cells. That way, the actual rendering would still be done by WP-Table Reloaded.
    But after thinking about it again, the "wp_table_reloaded_cell_content" really would be the best approach.

    Best wishes,
    Tobias

  5. lambethboy
    Member
    Posted 4 years ago #

    Thanks a lot Tobias, I'll give that a go and let you know how I get one.

    Best Wishes,
    Bill.

  6. lambethboy
    Member
    Posted 4 years ago #

    I've tried updating my code to do as you suggested, but I don't seem to be able to access the row and column numbers.

    Am I doing something wrong, for example -

    function wp_table_reloaded_portion_cell($cell_content, $table_id, $row, $col) {
    	return "$row $col";
    }
    
    add_filter('wp_table_reloaded_cell_content', 'wp_table_reloaded_portion_cell');

    Gives me -
    Warning: Missing argument 2 for wp_table_reloaded_portion_cell() in /share/..../wp-content/plugins/wp-table-reloaded-extensions.php on line 15

    Are the arguments passed to the filters a different way?

    Thanks a lot,
    Bill.

  7. TobiasBg
    Member
    Posted 4 years ago #

    Hi Bill,

    this happens because your function does not get those arguments passed. You need to tell WordPress, how many arguments the function expects, so that all of them get passed.

    If you change your add_filter call to

    add_filter('wp_table_reloaded_cell_content', 'wp_table_reloaded_portion_cell', 10, 4);

    In that code, the 10 is the priority the filter has (to determine the order of execution if there is more than one function hooked to the filter). 10 is the default, so no need to change it.
    The 4 is the important part: That is the number of arguments that your function has/expects. In your case it is 4 (cell content, ID, row and column).

    Best wishes,
    Tobias

  8. lambethboy
    Member
    Posted 4 years ago #

    Hi Tobias,

    Thanks, that works for me. You are a star!

    Best wishes,
    Bill.

  9. lambethboy
    Member
    Posted 4 years ago #

    Hi Tobias,

    Hopefully, my last point! I was hoping to have a user tag which would be in the first column. This would trigger some auto-inserted content and then the rest of the row would be set to span as we discussed earlier with #colspan# tags.

    Unfortunately the way the table cells are indexed starts in the bottom right hand corner, scans right to left and works upwards. The result is that any user tags in the leftmost column do not get processed until after the other cells in a row. This makes it impossible to add #colspan# data to fields as they have already been handled before we know they are needed.

    Is it possible to process the table cells from top/left to bottom/right instead?

    Thanks,
    Bill.

  10. TobiasBg
    Member
    Posted 4 years ago #

    Hi Bill,

    you are right, the cells are parsed from bottomr/ight to top/left.
    I don't like doing this, but that's the only chance for the plugin to detect colspans and rowspans properly (I have to know how many cells are colspanned/rowspanned, so that I can put the appropriate number as the value for the argument which is in the first cell of the rowspan/colspan group).

    So, no, unfortunately it is not possible to revert the processing order.

    I see two options that you have:
    Either put your user tag in the last column of the row (would probably require some teaching to the users),
    or (and that's probably the better solution): Do a pre-processing and add the #colspan# trigger word in the "wp_table_reloaded_post_load_table" hook.
    That hook will give you the entire table, and you could do your own processing there (i.e. from top/left to bottom/right).
    Then, if you find your user tag, just set the remaining columns of that row to #colspan#.
    Do you know what I mean?

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Topic