src/js/extensions/table/tableDataHandler.js
function addTbodyOrTheadIfNeed(tableData) {
  const [header] = tableData;
  const cellCount = header.length;
  let added = true;

  if (!cellCount && tableData[1]) {
    util.range(0, tableData[1].length).forEach(colIndex => {
      header.push(createBasicCell(0, colIndex, 'TH'));
    });
  } else if (tableData[0][0].nodeName !== 'TH') {
    const newHeader = util.range(0, cellCount).map(colIndex => createBasicCell(0, colIndex, 'TH'));

    [].concat(...tableData).forEach(cellData => {
      if (cellData.elementIndex) {
        cellData.elementIndex.rowIndex += 1;
      }
    });

    tableData.unshift(newHeader);
  } else if (tableData.length === 1) {
    const newRow = util.range(0, cellCount).map(colIndex => (
      createBasicCell(1, colIndex, 'TD')
    ));

    tableData.push(newRow);
  } else {
    added = false;
  }

  return added;
}
function addTbodyOrTheadIfNeed(tableData) {
  const [header] = tableData;
  const cellCount = header.length;
  let added = true;

  if (!cellCount && tableData[1]) {
    util.range(0, tableData[1].length).forEach(colIndex => {
      header.push(createBasicCell(0, colIndex, 'TH'));
    });
  } else if (tableData[0][0].nodeName !== 'TH') {
    const newHeader = util.range(0, cellCount).map(colIndex => createBasicCell(0, colIndex, 'TH'));

    [].concat(...tableData).forEach(cellData => {
      if (cellData.elementIndex) {
        cellData.elementIndex.rowIndex += 1;
      }
    });

    tableData.unshift(newHeader);
  } else if (tableData.length === 1) {
    const newRow = util.range(0, cellCount).map(colIndex => (
      createBasicCell(1, colIndex, 'TD')
    ));

    tableData.push(newRow);
  } else {
    added = false;
  }

  return added;
}
function addTbodyOrTheadIfNeed ( tableData ) { const [ header ] = tableData ; const cellCount = header . length ; let added = true ; if ( ! cellCount && tableData [ 1 ] ) { util . range ( 0 , tableData [ 1 ] . length ) . forEach ( colIndex => { header . push ( createBasicCell ( 0 , colIndex , 'TH' ) ) ; } ) ; } else if ( tableData [ 0 ] [ 0 ] . nodeName !== 'TH' ) { const newHeader = util . range ( 0 , cellCount ) . map ( colIndex => createBasicCell ( 0 , colIndex , 'TH' ) ) ; [ ] . concat ( ... tableData ) . forEach ( cellData => { if ( cellData . elementIndex ) { cellData . elementIndex . rowIndex += 1 ; } } ) ; tableData . unshift ( newHeader ) ; } else if ( tableData . length === 1 ) { const newRow = util . range ( 0 , cellCount ) . map ( colIndex => ( createBasicCell ( 1 , colIndex , 'TD' ) ) ) ; tableData . push ( newRow ) ; } else { added = false ; } return added ; }
Add tbody or thead of table data if need.
@param {Array.<Array.<object>>} tableData - table data
@returns {boolean}
@ignore
Add tbody or thead of table data if need .