Add row after copy paste

Posted by: chandrasekar_keerthana on 1 April 2020, 8:58 pm EST

  • Posted 1 April 2020, 8:58 pm EST

    Hi Team,
    When I copy paste a value and try to add a new record while pasted cell/row is till highlighted, the new row doesn't get added. Only after I click elsewhere the row appears. Is this an expected behavior or is something wrong here?
    Also we try to format the newly added row, in our application which is also breaking as the row isn't appearing. Below is the code we use to format:

    sheet._rows.forEach(function (record, index) {
    if (record._data.recored.ID == "" || record._data.record.ID == null) {
    sheet.applyCellsStyle({
    backgroundColor: HEX_GRAY
    }, [new wijmo.grid.CellRange(index, range._col, index, range._col + 1)]);
    sheet.applyCellsStyle({
    backgroundColor: HEX_YELLOW
    }, [new wijmo.grid.CellRange(index, range._col + 2, index, range._col + 5)]);
    }
    });


    Also, here's an example with the wijmo version we're currently using in our application.
    https://fkuku.csb.app/

    Thanks,
    Keerthana
  • Marked as Answer

    Replied 2 April 2020, 3:54 pm EST

    Hi Keerthana,

    You just need to commit the pasted row and refresh the CollectionView of the FlexSheet:
    document.getElementById('btn').addEventListener('click', () => {
    .....
    flexSheet.collectionView.commitEdit();
    flexSheet.collectionView.commitNew();
    flexSheet.collectionView.refresh();
    });

    https://codesandbox.io/s/sharp-spence-cjzzl

    This workaround may also resolve your issue of formatting.

    Let us know if case you run into any issues.

    Regards,
    Ashwin

  • Replied 5 April 2020, 6:03 pm EST

    It works. Thanks Ashwin.
  • Replied 20 April 2020, 1:08 am EST

    Hi Team,
    The above fix works for the add row scenario. But when I copy paste a row and without moving the focus, I do some validations and based on validation i'm setting value in a column for that record, but when I iterate through the rows of the sheet, it doesn't have the value set against it. On clicking elsewhere, the value appears again. Please provide your inputs on a possible workaround.

     sheet.rows.forEach(function (record, index) {
    if (index > 0)//No formats applied to the Header Row
    // index += 1;
    if (record._data.VALIDATION_MESSAGE.indexOf(STATUS_LOCKED) !== -1) {
    sheet.applyCellsStyle({
    color: '#000000',
    backgroundColor: '#FBBBED'
    }, [new wijmo.grid.CellRange(index, Range._col, index, Range._col2)]);
    }
    else if (record._data.VALIDATION_MESSAGE.indexOf(VALIDATION_STATUS_OK) !== -1) {
    sheet.applyCellsStyle({
    color: '#006400',
    backgroundColor: '#88e188'
    }, [new wijmo.grid.CellRange(index,Range._col, index, Range._col)]);
    }
    else if (record._data.VALIDATION_MESSAGE.indexOf(DIRTY_RECORD_MARKER) !== -1) {
    sheet.applyCellsStyle({
    color: '#ffffff',
    backgroundColor: HEX_GRAY
    }, [new wijmo.grid.CellRange(index, Range._col, index, Range._col)]);
    }
    else if (record._data.VALIDATION_MESSAGE.indexOf(STATUS_OK) !== -1) {
    sheet.applyCellsStyle({
    color: '#006400',
    backgroundColor: '#88e188'
    }, [new wijmo.grid.CellRange(index, Range._col, index, Range._col)]);
    }
    else if (record._data.VALIDATION_MESSAGE.indexOf(STATUS_ERROR) !== -1) {
    sheet.applyCellsStyle({
    color: '#ffffff',
    backgroundColor: '#ff0000'
    }, [new wijmo.grid.CellRange(index,Range._col, index, Range._col)]);
    }

    })



    Thanks,
    Keerthana
  • Replied 20 April 2020, 4:19 pm EST

    Hi Keerthana,

    The issue is similar to the previous issue. In the FlexSheet, whenever a data is edited, pasted or deleted, it needs to be committed either by pressing Enter or calling the commitEdit method.
    So, to resolve your issue, simply handle the pasted event and call the commitEdit method again:
    flexsheet.pasted.addHandler(function(s, e) {
    s.collectionView.commitEdit();
    });

    ~regards
  • Replied 20 April 2020, 9:48 pm EST

    Got it. thanks for the prompt reply Ashwin.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels