Flexsheet Insert row after Sorting

Posted by: chandrasekar_keerthana on 27 January 2019, 8:01 pm EST

  • Posted 27 January 2019, 8:01 pm EST

    Hi Team,

    I am trying to add a row to my flexsheet using Insert Row method and assign the data model to the row’s dataItem with code as follows:

    active_sheet.insertRows(selectedRow);

    var newrow = //A custom row with some default values

    let row = active_sheet.rows[selectedRow];

    $.extend(row.dataItem, newrow)

    This is based on your comments from the following post:

    https://www.grapecity.com/en/forums/wijmo/flexsheet-sort-after-inser

    In my case I am creating Flexsheet object using

    new wjmo.grid.sheet.Flexsheet(#Id); and adding a bound sheet with observable array

    as data source.

    I have integrated the recent Wijmo build -wijmo-5.20183.567 into my solution and I’m facing the following issue:

    I am formatting the sheet by painting its cells.So each time I add an new row,based on the new range I am calling the format function to paint the sheet using applycellsStyles method.This works fine the first time I add a row and Sort.The second time I again add a row and after sorting it loses the format and breaks. The sheet.evaluate function throws the below error:

    ‘Cannot read property ‘evaluate’ of undefined’

    Code:

    sheet.updatedView.addHandler(function (s, e) {

    aggData = Enumerable.From(data).Select(“$.sheet.evaluate($.” + col.binding + “)”).Sum();

    }

    Can you please help me with this.

    Thanks,

    Keerthana

  • Posted 28 January 2019, 6:35 pm EST

    Hi Keerthana,

    We are sorry but we are unable to replicate the issue at our end. Could you please have a look at the following sample and let us know what we are missing in the sample to replicate the issue;

    https://stackblitz.com/edit/js-psrqjt?file=index.js

    Also from the error message and code snippet you shared, it seems that $.sheet is not returning undefined, please make sure that it is returning the right value i.e. flexsheet instance.

    ~Sharad

  • Posted 30 January 2019, 8:47 pm EST

    Hi Sharad,

    The default row item is a typescript class with getters and setters which I want to be cloned into the new row’s dataItem.

    $.extend(newRow.dataItem, defaultRow)

    This seems to work fine the first time i add a row after sorting. But breaks at InsertRows() method, the second time. Any idea on what’s happening?

    Pls note that we’re using observable arrays as the sheet’s data source.

    Thanks,

    Keerthana

  • Posted 31 January 2019, 4:20 pm EST

    Hi Keerthana,

    Please refer to the following post which discusses a similar issue and let us know if this doesn’t work for you.

    https://www.grapecity.com/en/forums/wijmo/insert-row-in-flexsheet---

  • Posted 31 January 2019, 9:11 pm EST

    Hi Sharad,

    The solution mentioned in that post seems to work. Thank you.

    I see one minor issue though:

    After sorting, if I add a new row, the first time it retains the cursor in the newly added row. But the second time, it moves the cursor below two rows to the current position. I see this behavior in the snippet you had shared earlier as well.

    The thing is, we have custom drop downs embedded in the wijmo sheet in our project and we set the data selected from dropdown, based on the row number from the sheet’s selection field. Per the above issue description, the value seems to update in wrong cells.

    Please take a look at it.

    ~Keerthana

  • Posted 3 February 2019, 4:19 pm EST

    Hi Keerthana,

    We are able to replicate the issue at our end and hence forwarded it to the concerted team for further investigation of the issue(Internal tracking Id: 365643). We will let you know as we get an update on this.

    Further could you please let us know how you are implementing the dropdowns like using formatItem or prepareCellForEdit event, is it visible in only edit mode or normal cell mode so that in the meantime we may suggest you an alternative solution(if possible) instead of depending on the sheets selection field. Some code snippets or sample would be really appreciated.

  • Posted 4 February 2019, 5:46 pm EST

    Hi Sharad,

    Thanks for checking.

    We are calling a method to render the custom drop down from the prepareCellForEdit event for the cell. We use the sencha framework along with Wijmo, for our application. So on clicking a cell for edit we render the dropdown and assign the value selected to the sheet’s cell in the onSelect event of the combobox.

    var selectedRow = activesheet.selection.row;

    activesheet._rows[selectedRow]._data.YEAR = rec.data.YEAR;

    Also, there’s another issue I see with sort. As suggested in the other post, I have modified my code to use observable array wrapped in collectionView.

            data=new wijmo.collections.CollectionView(new wijmo.collections.ObservableArray(getData()), {
                newItemCreator: () => {
                    return new dataRecord()
                }
            }));
    

    The above method populates my sheet with 3 default rows. When i use formula references on these 3 rows and sort, it seems to work fine. But when I add a new row and use formula reference in this row as well, and then sort again, it doesn’t seem to work right.

    active_sheet.beginUpdate();

    active_sheet.insertRows(selectedRow,ROWCOUNT);

    active_sheet.endUpdate();

    attached a screenshot for your reference. pls check.

  • Posted 5 February 2019, 7:23 pm EST

    Hello,

    We are sorry, the attached screenshot is missing.

    Also, please share the code snippet how you are setting the Formula reference for the newly added row.

    Please share a stripped down sample depicting your issue for investigation.

    ~Manish

  • Posted 5 February 2019, 8:28 pm EST - Updated 3 October 2022, 11:12 am EST

    Hi Manish,

    I’ve been using simple formula like (=AC2+AD2) in AE2 and similar formula in the other cells too.

    Thanks.

  • Posted 7 February 2019, 12:03 am EST

    Hi Keerthana,

    For the issue regarding selection, instead of assigning the value to the selection, you may assign the value to the activeEditor of the sheet.

    Please have a look at the following same which demonstrates the same and let us know if this doesn’t work for you:

    https://codesandbox.io/s/ql6pymm506

    Regarding the formula issue, if we understand correctly the issue you are facing is that formulas are not updated if we insert rows after sorting. Please confirm that this is the same issue you are facing so that we could add you as correspondence for the issue(Id# 365642). If you are facing a different issue could you please let us know the steps that we could follow to replicate the issue?

  • Posted 7 February 2019, 4:16 am EST

    Hi Sharad,

    Thanks for the update. i’ll try it out.

    Yes, it is the same formula reference issue.

  • Posted 7 February 2019, 3:38 pm EST

    Thanks for confirming. We have added you as correspondence for the case and will let you know about any updates regarding the issue.

  • Posted 7 February 2019, 4:44 pm EST

Need extra support?

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

Learn More

Forum Channels