Unfortunately, you cannot use quill-better-table with ngx-quill wrapper. ngx-quill is still based on quilljs v1. quill-better-table requires quilljs v2.0.0-dev.3. You can read about that in the Requirements section: here
I can share with you how I implemented simple paste and read table in my case. Its inspired by this article and created with custom block. And its not a correct way to add elements to quill. But we are using editor internally so we are sure that it is in safe hands.
- Create a new 'Block Embed' like this:
import Quill from 'quill';
const BlockEmbed = Quill.import('blots/block/embed');
export class TableBlockEmbed extends BlockEmbed {
static blotName = 'TableBlockEmbed';
static tagName = 'table';
static create(value) {
const node = super.create();
let valueToReturn = value;
if (!value.includes('assignedTableId')) {
const tableId = `assignedTableId-${Date.now()}`;
valueToReturn = value
.replace('#tableId', `#${tableId}`)
.replace('table-layout: fixed;', '');
node.setAttribute('id', tableId);
} else {
const existedId = valueToReturn.match(/#assignedTableId-(\d+)/i)[1];
node.setAttribute('id', `assignedTableId-${existedId}`);
}
node.innerHTML = this.transformValue(valueToReturn);
return node;
}
static transformValue(value) {
let handleArr = value.split('\n');
handleArr = handleArr.map(e => e.replace(/^[\s]+/, '')
.replace(/[\s]+$/, ''));
return handleArr.join('');
}
static value(node) {
return node.innerHTML;
}
}
- Run registration of new embed block in the constructor of your component which uses ngx-quill:
constructor() {
Quill.register(TableBlockEmbed, true);
}
- add on editor Created this code below. (you can of course add/remove styles here you need. I added for example margin: 0 auto !important; because I want to force table to be always centered):
onEditorCreated(quill: Quill): void {
quill.clipboard.addMatcher('TABLE', (node, delta) => {
const Delta = Quill.import('delta');
const tableTagStyles = node.getAttribute('style');
return new Delta([
{
insert: {
TableBlockEmbed:
`<style>#tableId {${tableTagStyles} margin: 0 auto !important; }</style>` + delta.ops[0].insert.TableBlockEmbed
}
}
]);
});
}
- I added also some styles:
quill-view,
quill-editor{
::ng-deep {
table {
width: 100%; // if table has no width - then give it by default 100%
max-width: 100% !important;
box-sizing: border-box;
}
}
}
I know this solution is just workaround but until waiting for ngx-quill based on quill 2, I was able at least to give the feature of pasting tables inside the editor which looks quite nice.
Example:
table in office word:

table in ngx-quill:

table in excel:

table in ngx-quill:

Quill table
How do I fix this error I get whenever I try to register quill-better-table with my quill editor component in Angular 8? - Stack Overflow
How to bind data to the editor
Table in ngx-quill
» npm install ngx-quill
» npm install ngx-quill-v2
Hi has anyone used quill in angular 6 and implemented table in the editor. I've used quill 2.0.0 in angular 6 the table works fine but it didn't patch data like text. In the body. Is there any solution for it has anyone done it or any kind of insights on this topic would we great.
Thank you!
I managed to do this after some time thanks to this fiddle and a bit of playing around.See here.
component.html:
<quill-editor [(ngModel)]="editorContent"
[options]="editorOptions"
(ready)="onEditorCreated($event)"
(change)="onContentChanged($event)"></quill-editor>
component.ts:
public editor;
public editorContent = '<h3>Type Something...</h3>';
public editorOptions = {
theme: 'snow',
modules: {
toolbar: {
container:
[
[{ 'placeholder': ['[GuestName]', '[HotelName]'] }], // my custom dropdown
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'] // remove formatting button
],
handlers: {
"placeholder": function (value) {
if (value) {
const cursorPosition = this.quill.getSelection().index;
this.quill.insertText(cursorPosition, value);
this.quill.setSelection(cursorPosition + value.length);
}
}
}
}
}
};
constructor(private elem: ElementRef) {
}
onEditorCreated(quill) {
this.editor = quill;
console.log('quill is ready! this is current quill instance object', quill);
}
onContentChanged({ quill, html, text }) {
console.log('quill content is changed!', quill, html, text);
}
ngAfterViewInit() {
// Update your dropdown with labels
let placeholderPickerItems = this.elem.nativeElement.querySelectorAll('.ql-placeholder .ql-picker-item');
placeholderPickerItems.forEach(item => item.textContent = item.dataset.value);
this.elem.nativeElement.querySelector('.ql-placeholder .ql-picker-label').innerHTML
= 'Insert Data Field ' + this.elem.nativeElement.querySelector('.ql-placeholder .ql-picker-label').innerHTML;
}
Output:
Screenshot of Output
Hope this helps!
For more recent angular 8 projects, the configuration options are here: https://github.com/KillerCodeMonkey/ngx-quill#config
And this can be done in html via
<quill-editor [modules]="editorOptions" ></quill-editor>
and the js class
export class Component {
editorOptions= {
toolbar: [[{ 'list': 'bullet' }]]
};
}
