Rows inserted at wrong position in flexsheet after sort

Posted by: chandrasekar_keerthana on 29 January 2020, 5:37 am EST

    • Post Options:
    • Link

    Posted 29 January 2020, 5:37 am EST - Updated 3 October 2022, 5:46 pm EST

    Hi team,

    We recently integrated 5.20192.631 version of wijmo into our solution. We are observing an issue with the sort functionality. After sorting the data, if I try to insert a row to my flexsheet, the row gets added to some random position from where the cursor is placed.

    We use an observable array as our itemsource and below is the method we use to insert a custom row into the flexsheet.

    var selectedRow = active_sheet.selection.row;

    active_sheet.beginUpdate();

    active_sheet.itemsSource.beginUpdate();

    active_sheet.insertRows(selectedRow, ROWCOUNT);

    while (ROWCOUNT > 0) {

    newrow = new WijmoCustomRecord();

    newrow.YEAR = 2020;

    active_sheet.sheets[0].itemsSource.splice(selectedRow + i - 1, 1, newrow);

    ROWCOUNT–;

    i++;

    }

    active_sheet.itemsSource.endUpdate();

    active_sheet.endUpdate();

    Thanks,

    Keerthana

  • Posted 30 January 2020, 2:47 am EST

    Hi Keerthana,

    This is expected behavior because you are adding new items when the data is sorted. The data is inserted at the correct position but since the sorting is applied, the FlexSheet gets sorted automatically with the new data. Therefore, it seems like the data is added in a random position.

    Unfortunately, we cannot change this behavior because the CollectionView needs to refresh after adding the new itemsSource which will automatically sort it again. If we will no refresh the view, then only empty data rows will be displayed on the FlexSheet.

    I hope this clears your doubts.

    Regards,

    Ashwin

  • Posted 30 January 2020, 5:08 am EST

    Hi Ashwin,

    Thanks for the clarification.

    Please let me know how to identify the sorted position of the newly added rows/existing row. Because we apply certain formatting on the record based on few criteria.

    Thanks,

    Keerthana

  • Posted 31 January 2020, 3:21 am EST

    Hi Keerthana,

    We are sorry, in this case, there is no way to find the new position of the newly selected item if sorting is applied.

    As we understand, you are applying style using the applyCellsStyle() method. In this case, we recommend using the itemFormatter or formatItem to format the FlexSheet.

    This allows you to add the items dynamically. It can be used to format based on dataitem content.

    sheet.formatItem.addHandler(function(s,e){
    if(e.panel.cellType==1){
      if(s.rows[e.row].dataItem.country=='US'){
         e.cell.style.color='red';
      }
    }
    })
    

    Hope it helps!

    Regards,

    Manish Gupta

Need extra support?

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

Learn More

Forum Channels