Skip to content

Commit

Permalink
feat: adds option to save empty rows
Browse files Browse the repository at this point in the history
  • Loading branch information
alomoa committed Jul 24, 2023
1 parent 605a73d commit 408898e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ var editor = EditorJS({
| ------------------ | -------- | ---------------------------------------- |
| `rows` | `number` | initial number of rows. `2` by default |
| `cols` | `number` | initial number of columns. `2` by default |
| `withHeadings` | `boolean` | toggle table headings. `false` by default |
| `withHeadings` | `boolean`| toggle table headings. `false` by default |
| `allowEmptyRows` | `boolean`| toggle saving empty rows. `false` by default |

## Output data

Expand Down
9 changes: 7 additions & 2 deletions src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default class Table {
this.data = data;
this.config = config;

/**
* Config default
*/
this.config.allowEmptyRows = config.allowEmptyRows ?? false;

/**
* DOM nodes
*/
Expand Down Expand Up @@ -934,8 +939,8 @@ export default class Table {
const cells = Array.from(row.querySelectorAll(`.${CSS.cell}`));
const isEmptyRow = cells.every(cell => !cell.textContent.trim());

if (isEmptyRow) {
continue;
if(!this.config.allowEmptyRows && isEmptyRow){
continue;
}

data.push(cells.map(cell => cell.innerHTML));
Expand Down

0 comments on commit 408898e

Please sign in to comment.