sort

Sorts the rows in the range.

Parameters

sort Number | Object | Array

Determines the action performed by the method.

  • Passing a number n sorts the nth column in the range, in ascending order.
  • Passing a { column: Number, ascending: Boolean } sorts the respective column in ascending / descending order, based on the ascending parameter. The column index is relative to the beginning of the range.
  • Passing an array of { column: Number, ascending: Boolean } objects sorts each column, specified by the index.

Example - sort a single column

    <div id="spreadsheet"></div>
    <script type="text/javascript" charset="utf-8">

        $("#spreadsheet").kendoSpreadsheet();

        var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");

        var sheet = spreadsheet.activeSheet();

        var values = [
            [ 1, 2, 3 ],
            [ 7, 8, 9 ],
            [ 4, 5, 6 ]
        ];

        sheet.range("A1:C3").values(values);

        sheet.range("A1:C3").sort(1);
    </script>

Example - sort a column in descending order

    <div id="spreadsheet"></div>
    <script type="text/javascript" charset="utf-8">

        $("#spreadsheet").kendoSpreadsheet();

        var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");

        var sheet = spreadsheet.activeSheet();

        var values = [
            [ 1, 2, 3 ],
            [ 7, 8, 9 ],
            [ 4, 5, 6 ]
        ];

        sheet.range("A1:C3").values(values);

        sheet.range("A1:C3").sort({ column: 2, ascending: false });
    </script>

In this article