Sorting
This section covers the methods to handle the table sortingDocumentation
Methods
Method | Description |
---|---|
orderBy | Sorting the data by a column.
orderBy(column: number, direction?: orderByDirection): Promise<void>
@param column - column number. @param direction - sorting direction. Default is descending. POST /api/:guid/orderby
|
Examples
Sorting the data in a column
NodeJS
PHP
import { Client, orderByDirection } from '@jspreadsheet/client'; // Access token const token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz'; // Spreadsheet Guid const guid = '15eb1171-5a64-45bf-be96-f52b6125a045'; // Create a new client const client = new Client(token); // Get the spreadsheet instance const spreadsheet = client.getSpreadsheet(guid); // orderByDirection.Asc = Ascending order // orderByDirection.Desc = Descending order // Sort column spreadsheet.orderBy(2, orderByDirection.Asc).then(() => { // It worked correctly }) .catch((err) => { // Something went wrong console.log(err); });
<?php require 'vendor/autoload.php'; use jspreadsheet\Jspreadsheet; // Access token $token = 'MSwzMTJmZWQzMWYyYTI1OWQ5OGVhMWYxOWNhMDNhYWY3ZTA2ZmVmMWQz'; // Spreadsheet Guid $guid = '15eb1171-5a64-45bf-be96-f52b6125a045'; // Create the client instance $client = new Jspreadsheet($token); // Get the spreadsheet instance $spreadsheet = $client->getSpreadsheet($guid); // \jspreadsheet\Columns::ASC = Ascending order // \jspreadsheet\Columns::DESC = Descending order // Sort column $result = $spreadsheet->getColumn(2)->orderBy(\jspreadsheet\Columns::ASC); // Result with the new order applied print_r($result); // {"success": 1, "message": "Updated", "order": [8,7,6,5,4,3,2,1,0,9]}