4

I am trying to insert a table into react-quill using the quill-better-table library. I notice that a related plain js example here: https://codepen.io/soccerloway/pen/WWJowj uses the function quill.getModule('better-table') to get the module and then insert the table. I tried to do this using react-quill and react-quill-with-table but the function is not defined. Can the react version of the library work with quill-better-table?

import ReactQuill, { Quill, Mixin, Toolbar } from 'react-quill-with-table'; // ES6
import QuillBetterTable from "quill-better-table";

export default function MyQuillTextEditor(props) {

const modules = {
    toolbar: [
      [{ 'header': [1, 2, false] }],
      ['bold', 'italic', 'underline','strike', 'blockquote'],
      [{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}],
      ['link', 'image'],
      ['clean']
    ],
    table: false, // disable table module
    "better-table": {
        operationMenu: {
            items: {
                unmergeCells: {
                 text: "Another unmerge cells name"
            }
         }
       }
     },
   keyboard: {
     bindings: QuillBetterTable.keyboardBindings
   }
  }

const  formats = [
    'header',
    'bold', 'italic', 'underline', 'strike', 'blockquote',
    'list', 'bullet', 'indent',
    'link', 'image'
  ]

let editor = null;

const addTable = (e) => {
    e.preventDefault();
    Quill.getModule("better-table");
}


return (
    <div>
          <ButtonGroup size="small" aria-label="small button group">
                            <Button onClick>Add Row</Button>
                            <Button>Add Column</Button>
                            <Button>Delete Table</Button>
                            <Button onClick={(event) =>addTable(event)}>Add Table</Button>
                        </ButtonGroup>
        <ReactQuill theme="snow"
            ref={(el) =>{editor = el}}
            modules={modules}
            formats={formats}
            theme="snow"
            >

        </ReactQuill>
    </div>
   )
}
dimlee
  • 452
  • 1
  • 10
  • 22

2 Answers2

3

Right now, you can't use quill-better-table with react-quill.

you can look here for more info: https://github.com/soccerloway/quill-better-table/issues/42

  • For me the solution was use this https://www.npmjs.com/package/react-quill-with-table instead of https://www.npmjs.com/package/react-quill, and use this module https://github.com/volser/quill-table-ui for the table usage – andres martinez Feb 16 '23 at 04:49
1

I have same problem and now I've solved it. u can try

Quill.getModule("better-table");

to

 this.quillRef.getEditor().getModule('better-table');

and

<ReactQuill theme="snow"
    ref={(el) =>{editor = el}}
    modules={modules}
    formats={formats}
    theme="snow"
    >

to

 <ReactQuill theme="snow"
    ref={(el) =>{this.quillRef = el}}
    modules={modules}
    formats={formats}
    theme="snow"
    >
Gato0w0
  • 11
  • 1