Skip Rows while sorting data

Posted by: m.holland-moritz on 13 October 2021, 4:51 am EST

    • Post Options:
    • Link

    Posted 13 October 2021, 4:51 am EST

    Hello Team,

    i am facing a problem in my application. In the first 2 rows there are valuable information, that need to be fixed at this position to keep up the functionality of my application, but if my client is using the normal sorting function of the framework they probably do that with the whole sheet, since they usually only have 1 datatable per sheet.

    Is there a way, that i can fix that rows to a specific row or just skip them, while sorting?

    I tried freezepane and protecting the sheet, but that doesn’t work for me.

    Regards

    Maik

  • Posted 14 October 2021, 6:50 am EST

    Hi Maik,

    We are sorry but there is no direct method to achieve the required functionality but we could implement this by overriding the sort filter command. Please refer to the following code snippet and attached sample that demonstrates the same.

    
      let oldFilter = GC.Spread.Sheets.Commands.sortFilter.execute;
      GC.Spread.Sheets.Commands.sortFilter.execute = function (
        spread,
        options,
        isUndo
      ) {
        let { cmdOption } = options;
        let sheet = spread.getActiveSheet();
        let rowsToSkip = [0, 1];
        let changeRowState = (index, state) => sheet.setRowVisible(index, state);
        cmdOption.ignoreHidden = true;
        /*hide rows*/
        sheet.suspendPaint();
        rowsToSkip.forEach((row) => changeRowState(row, false));
        oldFilter.apply(this, arguments);
        /*unhide the rows*/
        rowsToSkip.forEach((row) => changeRowState(row, true));
        sheet.showRow(0);
        sheet.resumePaint();
      };
    }
    
    

    sample: https://codesandbox.io/s/infallible-fast-303eh?file=/src/index.js:633-1303

    Regards,

    Avinash

  • Posted 15 October 2021, 2:18 am EST

    Hey Avinash,

    that worked for me. I hope i can undo this by simply set:

    GC.Spread.Sheets.Commands.sortFilter.execute = oldFilter
    

    right?

    Thanks for help.

    Regards

    Maik

  • Posted 18 October 2021, 5:18 am EST

    Hi Maik.

    Yes, if you don’t want to add this feature you reassigning the oldFilter function should work fine let me know if you face any issues.

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels