jodit icon indicating copy to clipboard operation
jodit copied to clipboard

Jodit doesn't keep table borders

Open elshobokshy opened this issue 5 years ago • 13 comments

What jodit looks like :

Jodit

The result I'm getting :

Result

Any idea how to force jodit to give me the exact same HTML I visually see with the borders and all ?

elshobokshy avatar Nov 26 '19 11:11 elshobokshy

Another example is this : Sans titre With this result : Sans titre

elshobokshy avatar Nov 26 '19 12:11 elshobokshy

@elshobokshy You need append some styles what you use in your site in to editor

xdan avatar Nov 26 '19 12:11 xdan

@xdan isn't there a way to be able to get the exact same look without writing any custom styles ? My use of Jodit is to have the client create a table and get the exact same look. Isn't there a hacky way to get the exact same look? Like how to keep the borders and the cells width/height?

elshobokshy avatar Nov 26 '19 12:11 elshobokshy

@xdan otherwise, how to add a class to every table created using jodit automatically ? Something like class="jodit-table"

elshobokshy avatar Nov 26 '19 14:11 elshobokshy

You get a string from jodit editor. let it be data so you can manipulate data in onChange function of jodit editor as:

  if (data.includes("<td>")) {
    data = data.replaceAll("<td>", `<td style="border:1px solid black">`);
  }

and then using dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(data), }}

you will get borders

Chiragjain55551 avatar Jun 18 '21 09:06 Chiragjain55551

Hey @elshobokshy, How did you address this issue?

syedadil010 avatar Jul 05 '21 17:07 syedadil010

@syedadil010 I gave up and used tinymce v5 as it was easier :) That's why I closed the issue, I'm reopening if @xdan wants to fix this

elshobokshy avatar Jul 07 '21 18:07 elshobokshy

Based on the previos comment, I solved it like this:

if (content.includes("<table>")){ content = content.replaceAll("<table>", '"<table border="1" style="border-collapse:collapse;"'); }

NanTapia avatar Jul 10 '21 17:07 NanTapia

I just added this line in CSS for jodit-react table. it will work fine. td { border:solid 1px; }

yeasin-hossain avatar Jul 27 '22 15:07 yeasin-hossain

Another example is this : Sans titre With this result : Sans titre

Table itself is not adding for me and im getting node element must be in the editor it is saying. How to resolve it

MrArun005 avatar Aug 11 '22 08:08 MrArun005

The generated html do not have border style, i fixed it by adding style to the defaultOptions when creating attributes.

Jodit.defaultOptions.createAttributes = { table: { style: 'border:1px solid;border-collapse:collapse;width: 100%;', }, tr: { style: ' border: 1px solid;', }, td: { style: ' border: 1px solid;', }, };

ckc2715 avatar Feb 16 '24 03:02 ckc2715

image as stated from @ckc2715 I added the createAttribute option into the config using jodit-react const config = { theme: theme, createAttributes: { table: { style: 'border:1px solid #C5C6C8FF;border-collapse:collapse;width: 100%;', }, tr: { style: ' border: 1px solid #C5C6C8FF;', }, td: { style: ' border: 1px solid #C5C6C8FF;'}}, ...} this does indeed fix it. thanks @ckc2715 cheers 😸

CH-Chonsu avatar Apr 18 '24 12:04 CH-Chonsu