-
Notifications
You must be signed in to change notification settings - Fork 8
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
[Bug] Table cannot be displayed when edit again #12
Comments
Can you tell me specifically where this code should be placed? Because I am using the npm package form. After passing the html value of the table to the Richtext, I initialize this code and find that although this problem is solved, I cannot insert a table again, and the table cannot be fully displayed in the output html. |
Do you dependencies on |
If it weren't for the abov. const quill = new Quill('#root', options);
const delta = quill.clipboard.convert({ html });
const [range] = quill.selection.getRange();
quill.updateContents(delta, Quill.sources.USER);
quill.setSelection(
delta.length() - range.length,
Quill.sources.SILENT,
);
quill.scrollIntoView(); |
Our actual use may be more complicated than the demo. We did this code after getting the html when initializing the rich text component and when listening to html changes. The problem was temporarily solved. But another problem arose, that is, the table could not be displayed normally when inserted for the second time. We temporarily solved the problem by replace the span tag in the table in the html, but it seems that it did not solve it fundamentally. |
I did a workaround to get it working. Here is my code: const html = $(quillID).html();
$(quillID).html("");
const quillEditor = new Quill(quillID, options);
const delta = quillEditor.clipboard.convert({ html })
quillEditor.updateContents(delta, Quill.sources.USER); |
@attoae hello,I am using react-quill, so where should this code be placed? |
This library import { useEffect } from 'react';
import Quill from 'quill';
import QuillTableBetter from 'quill-table-better';
import 'quill/dist/quill.snow.css';
import 'quill-table-better/dist/quill-table-better.css';
Quill.register({
'modules/table-better': QuillTableBetter
}, true);
const options = {
theme: 'snow',
modules: {
toolbar: ['bold', 'italic', 'underline', 'strike', 'table-better'],
table: false,
'table-better': {
language: 'en_US',
menus: ['column', 'row', 'merge', 'table', 'cell', 'wrap', 'delete'],
toolbarTable: true
},
keyboard: {
bindings: QuillTableBetter.keyboardBindings
}
}
};
// The html here is sample data, the real data is what you get from the database.
const html = `
<table class="ql-table-better">
<tbody>
<tr>
<td data-row="row-jd3a" width="72" class="ql-cell-focused">
<p class="ql-table-block" data-cell="cell-wmy6"><br></p>
</td>
<td data-row="row-jd3a" width="72">
<p class="ql-table-block" data-cell="cell-tni4"><br></p>
</td>
</tr>
<tr>
<td data-row="row-cu2a" width="72">
<p class="ql-table-block" data-cell="cell-zmnp"><br></p>
</td>
<td data-row="row-cu2a" width="72">
<p class="ql-table-block" data-cell="cell-7o44"><br></p>
</td>
</tr>
</tbody>
</table>
`;
function Editor() {
useEffect(() => {
const quill = new Quill('#editor', options);
const delta = quill.clipboard.convert({ html });
const [range] = quill.selection.getRange();
quill.updateContents(delta, Quill.sources.USER);
quill.setSelection(
delta.length() - (range?.length || 0),
Quill.sources.SILENT,
);
quill.scrollIntoView();
}, []);
return (
<div id="editor"></div>
);
}
export default Editor; |
@attoae thanks, but i am using |
function Editor() {
const quillRef = useRef(null);
useEffect(() => {
if (quillRef.current) {
const quill = quillRef.current.getEditor();
const [range] = quill.selection.getRange();
quill.updateContents(delta, Quill.sources.USER);
quill.setSelection(
delta.length() - (range?.length || 0),
Quill.sources.SILENT,
);
quill.scrollIntoView();
}
}, [quillRef]);
return (
<ReactQuill ref={quillRef} theme="snow" modules={modules} />
);
} |
@attoae Thank you for your patience. I'll try first |
@attoae Excuse me for bothering you. In my scenario, I want to switch between edit mode and read mode, and the styles are somewhat different. So, I have two ReactQuill components, and I hope to change the display when clicking a button. Also, I want to display tables in read-only mode, but it is not working at the moment. Can you help me take a look? here is my |
import Delta from 'quill-delta';
const [value, setValue] = useState(new Delta());
const quillRef = useRef(null);
useEffect(() => {
if (quillRef.current || preview) {
const quill = quillRef.current.getEditor();
const [range] = quill.selection.getRange();
quill.setContents();
quill.updateContents(value.delete(1));
!preview && quill.setSelection(
value.length() - (range?.length || 0),
Quill.sources.SILENT,
);
!preview && quill.scrollIntoView();
}
}, [quillRef, preview]);
return (
<>
<ReactQuill
ref={quillRef}
key={preview ? 'preview' : 'edit'}
id={preview ? 'preview' : 'edit'}
theme={preview ? 'bubble' : 'snow'}
readOnly={preview}
modules={modules}
onChange={handleQuillValueChange}
/>
<button onClick={() => setPreview((value) => !value)} type="button">
{ preview ? 'Change Editor' : 'Change Preview' }
</button>
</>
); |
@attoae I used this code. But when i click the button, the table disappeared |
Using |
After the table is saved, it cannot be displayed when it is edited and displayed again
When edit showing
![image](https://private-user-images.githubusercontent.com/72329902/362236135-886e1f3c-ca7f-47a5-b0ba-e7a0a53035e1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NzcwMTIsIm5iZiI6MTczOTQ3NjcxMiwicGF0aCI6Ii83MjMyOTkwMi8zNjIyMzYxMzUtODg2ZTFmM2MtY2E3Zi00N2E1LWIwYmEtZTdhMGE1MzAzNWUxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE5NTgzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEwMzkwZTI5ZmViZDAzYTRmNWNiN2ZlZTNlMTc4NDI5NjJmYjAwYzU3MzNkNzliODgyZDRiYjg0YzY4MDQ5YjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.O5vIHpAOVGeZVNpWRiZ0dt3oWOP5VGH9OiCZv4tDioA)
The text was updated successfully, but these errors were encountered: