• Resolved Lukasz

    (@wpfed)


    Hi,

    I am attempting to create a default table variation with the header section toggled on. There is no boolean attribute to activate the header section it seems and instead it’s an array.

    I was able to add the header section with the below code but it then doesn’t activate the ‘create table wizard'(where user chooses amount of columns/rows before table is generated) and it also breaks the “insert row” function unless I also add the attribute body": [{"cells": [...

    wp.blocks.registerBlockVariation('core/table', {
    		name: 'my-table',
    		title: 'Table',
    		attributes: {
    			className: 'is-style-regular',
    			head: [
    				{
    				  cells: [
    					{
    					  tag: "th"
    					}
    				  ]
    				}
    			  ],
    		},
    		isDefault: true,
    	});

    If block variation can’t toggle the header section without losing the wizard and insert row functionality then is there another way of doing it?

    • This topic was modified 1 year, 10 months ago by Lukasz.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @wpfed!

    I was able to add the header section with the below code but it then doesn’t activate the ‘create table wizard’

    It is not currently possible to have the placeholder (wizard) appear for a Table variation like yours that includes a header. The Table block will display the placeholder when the head, body and foot sections are all empty. In this case head is non-empty.

    and it also breaks the “insert row” function unless I also add the attribute body”: [{"cells": [...

    It looks like you’ve found a bug here. You can also see it when you insert a Table block, add a header section, then delete all of the body rows. Would you mind opening a bug report in the Gutenberg repository?

    https://github.com/WordPress/gutenberg/issues/new/choose

    For now, I think the best you can do is specify a block variation that contains a preset number of header and body cells. The user will have to add or delete rows and columns as necessary.

    wp.blocks.registerBlockVariation('core/table', {
    	name: 'my-table',
    	title: 'Table',
    	attributes: {
    		className: 'is-style-regular',
    		head: [
    			{
    				cells: [
    					{ tag: "th", content: "" },
    					{ tag: "th", content: "" }
    				]
    			}
    		],
    		body: [
    			{
    				cells: [
    					{ tag: "td", content: "" },
    					{ tag: "td", content: "" }
    				]
    			}
    		],
    	},
    	isDefault: true,
    });
    Thread Starter Lukasz

    (@wpfed)

    Thank you @noisysocks I’ve been a little busy but will go ahead with the bug report. Thanks for the suggestion as well regarding the table cells and you are correct, I can reproduce the bug when deleting all the rows with header present, you can no longer add them back.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Table block variation with header section activated’ is closed to new replies.