Skip to main content

sortCells()

Description

Sorts data in the spreadsheet

Usage

sortCells(cell: string, dir: number): void;

Parameters

  • cell - (required) the id(s) of a cell(s) or a range of cells by which you want the data in the spreadsheet to be sorted
  • dir - (required) the direction of sorting:
    • 1 - ascending order
    • -1 - descending order

Example

const spreadsheet = new dhx.Spreadsheet("spreadsheet", {
topSplit: 1
});
spreadsheet.parse(data);

// sorts data on the first sheet
spreadsheet.sortCells("B2:B11", -1);

// sorts data on several sheets
spreadsheet.sortCells("Income!B2:B11, Report!B2:B11, Expenses!C2:C11", 1);
info

Use the topSplit property if you need to exclude the top rows from sorting.

Related sample: Spreadsheet. Initialization with multiple sheets

Related articles: Sorting data