Getting the number of displayed rows after applying a filter

Posted by: marius.runde on 14 July 2020, 7:03 am EST

    • Post Options:
    • Link

    Posted 14 July 2020, 7:03 am EST

    Hello,

    I’m using the default filters from SpreadJS to filter the content of my spreadsheet. Outside of the spreadsheet I want to display the number of rows that are displayed. This number first displays the total number of rows but when applying a filter I only want to get the number of displayed rows.

    Is there a way to get the number without iterating through all rows (which is done in this example: https://help.grapecity.com/spread/SpreadJSWeb/scfiltresult.html

    This is how I activate the filters:

    
    const filter = new GC.Spread.Sheets.Filter.HideRowFilter(
      new GC.Spread.Sheets.Range(0, 1, <<NUMBER_OF_ROWS>>, <<NUMBER_OF_COLUMNS>>));
    this.sheet.rowFilter(filter);
    filter.filterDialogVisibleInfo({
      sortByValue: true,
      sortByColor: false,
      filterByColor: false,
      filterByValue: true,
      listFilterArea: true
    });
    
    

    And this is how I listen to the filter event:

    
    this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.RangeFiltered, (event, info) => {
      // Here I want to get the number of currently displayed rows
    });
    
    

    Any help is appreciated :slight_smile:

  • Posted 15 July 2020, 6:37 am EST

    Hi,

    There is no direct API to achieve this functionality but you may use filter.toJSON() method to get info about the filter and then find the visible rows. Please refer to the following code snippet:

    sheet.bind(GC.Spread.Sheets.Events.RangeFiltered, (event, info) => {
        // Here I want to get the number of currently displayed rows
        let filterInfo = info.sheet.rowFilter().toJSON();
        let filteredOutCount = filterInfo.filteredOutRows.length;
        let totalRows = info.sheet.getRowCount();
    
        let totalVisibleRows = totalRows - filteredOutCount;
        console.log(totalVisibleRows);
      });
    

    Regards

  • Posted 15 July 2020, 7:51 am EST

    Hi Sharad,

    thanks for the recommended solution. This worked for us :slight_smile:

Need extra support?

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

Learn More

Forum Channels