-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can not create a table with a headers row and add dynamic data to the headers and the data cells #6734
Labels
type:question
This issue asks a question (how to...).
Comments
rezaimn
changed the title
can not create a table with a header row and add dynamic data to the header and the cells
can not create a table with a headers row and add dynamic data to the headers and the data cells
May 4, 2020
@jodator, can you take a look at it? |
Sorry, Can I take a look at what? |
I will look at this - @Mgsy was pinging me here :) |
Great, Thanks |
@rezaimn You can do it like this: const model = editor.model;
model.change( writer => {
// Create a table.
const table = tableUtils.createTable( writer, 2, 2 );
// Set it's "headingRows" attribute to 1.
writer.setAttribute( 'headingRows', 1, table );
// To simplify we'll take the first (only) data row.
const dataRow = table.getChild( 1 );
for ( const tableCell of dataRow.getChildren() ) {
// Each created table cell have an empty paragraph as a child.
const paragraph = tableCell.getChild( 0 );
// Crete a content to insert - here just "foo" text.
const text = writer.createText( 'foo' );
// Insert text to a paragraph.
const insertPosition = writer.createPositionAt( paragraph, 0 );
writer.insert( text, insertPosition );
}
// Use model.insertContent() to insert a created content.
// It will insert table at a current document selection position.
model.insertContent( table );
} ); |
Mgsy
added
pending:feedback
This issue is blocked by necessary feedback.
type:question
This issue asks a question (how to...).
labels
May 6, 2020
Thank you so much. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I want to create a table in Ckeditor 5 that must contain a header row and a data row. I have tried editor.execute to create a table with a header row and it was ok, but I don't know how to fill the header and data cells with my data programmatically.
I also tried TableUtils plugin, I could create a table and fill it with my data, but I don't know how to make my first row as the header with this method.
Is there any solution to fix each of the above ways I have tried?
thank you.
The text was updated successfully, but these errors were encountered: