Skip to content
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

Table Module: Deleting Rows or Columns Adds Instead of Deleting #4611

Open
ahmad-athra opened this issue Feb 22, 2025 · 0 comments
Open

Table Module: Deleting Rows or Columns Adds Instead of Deleting #4611

ahmad-athra opened this issue Feb 22, 2025 · 0 comments

Comments

@ahmad-athra
Copy link

Expected Behavior: Deleting a row or column should remove it from the table.

Actual Behavior: Deleting a row or column adds a new one instead.

code:
Repo: https://github.com/ahmad-athra/ng-text-editor/tree/master

  quillConfig:QuillModules = {
    imageResize: {},
    magicUrl: true,
    table: true,
    toolbar: {
      container: [
        [{ 'header': [1, 2, 3, false] }],
        [{'size': this.font_sizes}],
        ['bold', 'italic', 'underline', 'strike', 'clean'],        // toggled buttons
        [{ 'color': [] }, { 'background': [] }],
        ['blockquote', 'code-block'],
        [{ 'direction': 'rtl' }],
        ['link', 'image'],
        [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
        [{ align: [] }],
        [{ indent: "-1" }, { indent: "+1" }],
        [
          {
            table: [
              "insert-table",
              "insert-row-above",
              "insert-row-below",
              "insert-column-right",
              "insert-column-left",
              "delete-row",
              "delete-column",
              "delete-table",
            ],
          },
        ],
      ],
    }
  }

  quill!: Quill; // Quill instance
    // Get the Quill instance
    onEditorCreated(quill: Quill) {

      this.quill = quill;
      this.setupTableCommands();
    }
    setupTableCommands() {
      const toolbar = this.quill.getModule('toolbar') as any;

      const tableModule = this.quill.getModule('table') as any;

      // Find the table picker in the toolbar
      const tablePicker = toolbar.container.querySelector('.ql-table');

      if (tablePicker) {
        // Add click event listener to the table picker items
        tablePicker.addEventListener('click', (e: Event) => {

          const target = e.target as HTMLElement;
          if (target.classList.contains('ql-picker-item')) {
            const action = target.getAttribute('data-value');

            e.preventDefault();

            switch (action) {
              case 'insert-table':
                tableModule.insertTable(2, 2);
                break;
              case 'insert-row-above':
                tableModule.insertRowAbove();
                break;
              case 'insert-row-below':
                tableModule.insertRowBelow();
                break;
              case 'insert-column-left':
                tableModule.insertColumnLeft();
                break;
              case 'insert-column-right':
                tableModule.insertColumnRight();
                break;
              case 'delete-row':
                tableModule.deleteRow();
                break;
              case 'delete-column':
                tableModule.deleteColumn();
                break;
              case 'delete-table':
                tableModule.deleteTable();
                break;
            }

            if (action !== 'delete-row') {
              tableModule.balanceTables();
            }
          }
        });
      }
    }
// table
const Table = Quill.import("formats/table-container") as any;
const superCreate = Table.create.bind(Table);
Table.create = (value: any) => {
  const node = superCreate(value);
  node.classList.add('table');
  node.classList.add('table-bordered');
  return node;
};
Quill.register(Table, true);
  <!-- Custom -->
  <quill-editor
  style="display: block; width: 100%"
  [modules]="quillConfig"
  formControlName="textEditor"
  (onEditorCreated)="onEditorCreated($event)">
  </quill-editor>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant