# Sort DropDown Control

The sort dropdown control is used to sort HTML elements by the specified CSS selector using the HTML SELECT element. It is possible to sort text and numerical content.

```markup
<select data-grid-control="sort">
    <option data-type="initial" selected>Sort by</option>
    <option data-path=".title" data-direction="asc" data-type="text">Sort by title asc</option>
    <option data-path=".title" data-direction="desc" data-type="text">Sort by title desc</option>
    <option data-path=".price" data-direction="asc" data-type="number">Sort by price asc</option>
    <option data-path=".price" data-direction="desc" data-type="number">Sort by price desc</option>
</select>
```

#### Select data attributes

| Data Attribute    | Value                   | Description                                                                                        | Required |
| ----------------- | ----------------------- | -------------------------------------------------------------------------------------------------- | -------- |
| data-grid-control | sort                    | This attribute defines the control type.                                                           | Required |
| data-id           | any alphanumeric string | <p>This attribute may be used in the deep-link, </p><p>local storage, or complex filter logic.</p> | Optional |

#### Option elements data attributes

| Data Attribute | Value                 | Description                                            | Required |
| -------------- | --------------------- | ------------------------------------------------------ | -------- |
| data-path      | any CSS selector      | It defines the path to the item that should be sorted. | Optional |
| data-direction | asc, desc             | Sort direction                                         | Optional |
| data-type      | text, number, initial | Sort type                                              | Optional |
| data-skip      | \[^a-zA-Z0-9]+        | Defines a regex of characters that should be skipped.  | Optional |
| selected       |                       | The selected option                                    | Optional |

{% hint style="info" %}
The selected option should be marked with the **selected** attribute.
{% endhint %}

#### Sort Types

| Sort Type | Description                                                                    |
| --------- | ------------------------------------------------------------------------------ |
| text      | Sort by text content.                                                          |
| number    | Sort by numeric content.                                                       |
| initial   | <p>Sort by initial document order.</p><p><em>Added in DataGrid v1.0.2</em></p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.getdatagrid.com/controls/sort-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
