• Resolved ignoOre

    (@ignoore)


    Hi Tobias,

    want to tell you that tablepress is awesome, makes life so much easier ??
    But i′ve got a question too ??

    I want to make a cross-table an added my table via the import function from a .CSV. That worked perfectly.
    I just set the “first-row is the tableheader” off (so only have a tbody, but not a thead), because I don′t need a tableheader and all rows got to look the same way.
    Now I want to rotate the text in row-1 for 270° (= -90°).

    The Code HTML Code looks like:

    <table id="tablepress-12" class="tablepress tablepress-id-12">
    	<caption style="caption-side:bottom;text-align:left;border:none;background:none;margin:0;padding:0;">
    	</caption>
    
    	<tbody class="row-hover">
    
    		<tr class="row-1 odd">
    			<td class="column-1"></td>
    			<td class="column-2">SPALTE 1 Titel</td>
    			<td class="column-3">SPALTE 2 Titel</td>
    			<td class="column-4">SPALTE 3 Titel</td>
    		</tr>
    
    		<tr class="row-2 even">
    			<td class="column-1">ZEILE 1 Titel</td>
    			<td class="column-2">12</td>
    			<td class="column-3">28</td>
    			<td class="column-4">32</td>
    		</tr>
    
    		<tr class="row-3 odd">
    			<td class="column-1">ZEILE 2 Titel</td>
    			<td class="column-2">11</td>
    			<td class="column-3">4</td>
    			<td class="column-4">25</td>
    		</tr>
    
    	</tbody>
    </table>

    Can you maybe tell me if it′s possible to add some code into the function.php, that adds a <div> and <span> Tag into the <th>-Tag of all tablecells (maybe even only into the first-row), so it would look like this:

    <table id="tablepress-12" class="tablepress tablepress-id-12">
    	<caption style="caption-side:bottom;text-align:left;border:none;background:none;margin:0;padding:0;">
    	</caption>
    
    	<tbody class="row-hover">
    
    		<tr class="row-1 odd">
    			<td class="column-1"><div><span></span></div></td>
    			<td class="column-2"><div><span>SPALTE 1 Titel</span></div>/td>
    			<td class="column-3"><div><span>SPALTE 2 Titel</span></div></td>
    			<td class="column-4"><div><span>SPALTE 3 Titel</span></div></td>
    		</tr>
    
    		<tr class="row-2 even">
    			<td class="column-1">ZEILE 1 Titel</td>
    			<td class="column-2">12</td>
    			<td class="column-3">28</td>
    			<td class="column-4">32</td>
    		</tr>
    
    		<tr class="row-3 odd">
    			<td class="column-1">ZEILE 2 Titel</td>
    			<td class="column-2">11</td>
    			<td class="column-3">4</td>
    			<td class="column-4">25</td>
    		</tr>
    
    	</tbody>
    </table>

    Would be great if you have an idea…

    https://www.ads-software.com/plugins/tablepress/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    The best approach here probably is to hook into the tablepress_cell_content plugin filter hook. That gets the cell content as a parameter, but also the row number and table ID. With those, you could check if the cell belongs to the header row of the desired table and then add the extra HTML to the cell content.
    This post contains a similar (and even more complicated) example: https://www.ads-software.com/support/topic/adding-html-to-tables?replies=35#post-6544393

    Regards,
    Tobias

    Thread Starter ignoOre

    (@ignoore)

    Hey Tobias,

    thank you for the very fast hint! I hope I did it the right way, actually it looks so:

    add_filter( 'tablepress_cell_content', 'table_add_span', 10, 4 );
    	function table_add_span( $tablepress_cell_content, $table_id, $row_number, $column_number ) {
    	  if ($table_id>0) {
    		if ($column_number==1) {
    		  $temp=$tablepress_cell_content;
    		  $tablepress_cell_content = "<span>".$temp."</span>";
    		}
    	  }
    	  return $tablepress_cell_content;
    	}

    Could you maybe just tell me if the code seems to be ok? And for the $accepted_args I just took “4”, like the guys in the Thread you showed me did. Actually I have no idea what number I should add in there.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes, the value 4 for $accepted_args is correct.

    You might however want to use $row_number and no $column_number in

    if ($column_number==1) {

    Regards,
    Tobias

    Thread Starter ignoOre

    (@ignoore)

    You′re right, of course ??

    Is it possible to take if ($table_id>0) out , so it′s automatically for all tables. And take $column_number in function table_add_span( $tablepress_cell_content, $table_id, $row_number, $column_number ) out, to have less code? I mean like:

    add_filter( 'tablepress_cell_content', 'table_add_span', 10, 4 );
    	function table_add_span( $tablepress_cell_content, $table_id, $row_number ) {
    		if ($row_number==1) {
    		  $temp=$tablepress_cell_content;
    		  $tablepress_cell_content = "<span>".$temp."</span>";
    		}
    	  }
    	  return $tablepress_cell_content;
    	}
    Thread Starter ignoOre

    (@ignoore)

    Anyway…thanks a lot for your helf! I really appreciate it.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes, you could do both of that, but there’s no real point to doing this, I think.
    But good to hear that it works! ??

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    Thread Starter ignoOre

    (@ignoore)

    Hi Tobias,

    it′s me again. So the Plugin on top works perfectly, but now there′s a new Problem:
    I am trying to have a :hover on the row and column when i am “mouseover” a tablecell. I already have a Javascript for that, but need therefor <colgroup> right after <caption> and befor the <thead> elements.

    Can you give me a hint (maybe for another plugin) how to make the code look like this:

    <table id="tablepress-12" class="tablepress tablepress-id-12">
    	<caption style="caption-side:bottom;text-align:left;border:none;background:none;margin:0;padding:0;">
    	</caption>
    
        <colgroup></colgroup>
        <colgroup class="slim"></colgroup>
        <colgroup class="slim"></colgroup>
        <colgroup class="slim"></colgroup>
    
    	<tbody class="row-hover">
    
    		<tr class="row-1 odd">
    			<td class="column-1"><div><span></span></div></td>
    			<td class="column-2"><div><span>SPALTE 1 Titel</span></div>/td>
    			<td class="column-3"><div><span>SPALTE 2 Titel</span></div></td>
    			<td class="column-4"><div><span>SPALTE 3 Titel</span></div></td>
    		</tr>
    
    		<tr class="row-2 even">
    			<td class="column-1">ZEILE 1 Titel</td>
    			<td class="column-2">12</td>
    			<td class="column-3">28</td>
    			<td class="column-4">32</td>
    		</tr>
    
    		<tr class="row-3 odd">
    			<td class="column-1">ZEILE 2 Titel</td>
    			<td class="column-2">11</td>
    			<td class="column-3">4</td>
    			<td class="column-4">25</td>
    		</tr>
    
    	</tbody>
    </table>

    Is there a way, to make a plugin find out how many columns a table have and add this number of <colgroup class=”slim”></colgroup> Tags?

    Thanks a lot again, you′re doing an awesome job!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    adding a <colgroup> tag is very simple ?? TablePress can actually add those, it just doesn’t do it by default (as they are rarely used).
    To turn them on, just add this to the “functions.php” file in your theme (or a small new plugin):

    add_filter( 'tablepress_print_colgroup_tag', '__return_true' );

    If you want to modify the attributes of the individual <col> tags, you could do that by hooking into the tablepress_colgroup_tag_attributes filter hook that is available in the /classes/class-render.php file of TablePress.

    Regards,
    Tobias

    Thread Starter ignoOre

    (@ignoore)

    THIS is awesome! Thank you so much!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Put a div & span in the -Tag’ is closed to new replies.