Back to Handsontable

Layout direction

docs/content/guides/internationalization/layout-direction/layout-direction.md

18.0.035.4 KB
Original Source

Set the layout direction for right-to-left languages. Automatically inherit your HTML file's dir property, or set the layout direction manually.

[[toc]]

Overview

To properly display Handsontable's UI and data in LTR languages (such as English, Chinese, or Russian) and RTL languages (such as Arabic, Persian, or Hebrew), configure your grid's layout direction.

By default, Handsontable's layout direction is set automatically, based on on the value of your HTML document's dir attribute.

You can:

RTL support

If your app uses an RTL language, we recommend setting Handsontable's layout direction to RTL.

For Arabic, use Handsontable's built-in Arabic translation. For any other RTL language, add your own translation.

RTL demo

To try out Handsontable's RTL support, check out the demo below:

::: only-for javascript

::: example #example1 :hot-lang --js 1 --ts 2

@code @code

:::

:::

::: only-for react

::: example #example1 :react-languages --js 1 --ts 2

@code @code

:::

:::

::: only-for angular

::: example #example1 :angular-languages --ts 1 --html 2

@code @code

:::

:::

::: only-for vue

::: example #example1 :vue3-languages

@code

:::

:::

Elements affected by layout direction

Setting a different layout direction affects the behavior of the following areas of Handsontable:

ElementLTR layout directionRTL layout direction
Starting edgeThe left-hand edge is treated as the starting edge of the grid.The right-hand edge is treated as the starting edge of the grid.
Ending edgeThe right-hand edge is treated as the ending edge of the grid.The left-hand edge is treated as the ending edge of the grid.
Order of columns on the screenCell rendering flows from the left-hand side of the screen to right-hand side.

Cell (0, 0) is rendered in the grid's top-left corner. | Cell rendering flows from the right-hand side of the screen to left-hand side.

Cell (0, 0) is rendered in the grid's top-right corner. | | Text direction in cells | All cells inherit the LTR direction from the container element. | All cells inherit the RTL direction from the container element. | | Position of row headers | Row headers are rendered on the left-hand edge of the grid. | Row headers are rendered on the right-hand edge of the grid. | | Position of frozen columns | Columns are frozen at the left-hand edge of the grid. | Columns are frozen at the right-hand edge of the grid. | | Position of the fill handle | The fill handle displays in the bottom-right corner of the selection border. | The fill handle displays in the bottom-left corner of the selection border. | | Position of the selection handles, on mobile devices | On mobile devices, the selection handles display in the top-left and bottom-right corners of the selection border. | On mobile devices, the selection handles display in the top-right and bottom-left corners of the selection border. | | Custom borders | In the customBorders option:

  • The left-hand border is treated as the starting border.

  • The right-hand border is treated as the ending border. | In the customBorders option:

  • The right-hand border is treated as the starting border.

  • The left-hand border is treated as the ending border. | | Context menu and column menus | Menus' layout direction is left-to-right.

Submenus expand to the right. | Menus' layout direction is right-to-left.

Submenus expand to the left. | | Keyboard navigation | <kbd>Tab</kbd> moves one cell to the right.

<kbd>Shift</kbd>+<kbd>Tab</kbd> moves one cell to the left.

<kbd>Home</kbd> moves to the leftmost non-frozen cell of the current row.

<kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Home</kbd> moves to the top-left non-frozen cell of the grid.

<kbd>Shift</kbd>+<kbd>Home</kbd> extends the selection to the leftmost non-frozen cell of the current row.

<kbd>End</kbd> moves to the rightmost non-frozen cell of the current row.

<kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>End</kbd> moves to the bottom-right non-frozen cell of the grid.

<kbd>Shift</kbd>+<kbd>End</kbd> extends the selection to the rightmost non-frozen cell of the current row.

<kbd>Delete</kbd> deletes one character to the right of the cursor.

<kbd>Backspace</kbd> deletes one character to the left of the cursor. | <kbd>Tab</kbd> moves one cell to the left.

<kbd>Shift</kbd>+<kbd>Tab</kbd> moves one cell to the right.

<kbd>Home</kbd> moves to the rightmost non-frozen cell of the current row.

<kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>Home</kbd> moves to the top-right non-frozen cell of the grid.

<kbd>Shift</kbd>+<kbd>Home</kbd> extends the selection to the rightmost non-frozen cell of the current row.

<kbd>End</kbd> moves to the leftmost non-frozen cell of the current row.

<kbd>Ctrl</kbd>/<kbd>Cmd</kbd>+<kbd>End</kbd> moves to the bottom-left non-frozen cell of the grid.

<kbd>Shift</kbd>+<kbd>End</kbd> extends the selection to the leftmost non-frozen cell of the current row.

<kbd>Delete</kbd> deletes one character to the left of the cursor.

<kbd>Backspace</kbd> deletes one character to the right of the cursor. |

The list above is not exhaustive. Setting a different layout direction might affect other areas of Handsontable as well.

Set the layout direction

You can set the layout direction only at Handsontable's initialization. Any change of the layoutDirection option after the initialization (e.g. using the updateSettings() method) is ignored.

Set the layout direction automatically

You can set Handsontable's layout direction automatically, based on on the value of your HTML document's dir attribute. This is the default setting.

At Handsontable's initialization, add layoutDirection as a top-level grid option, and set it to 'inherit'. As this is the default setting, you can also skip setting the layoutDirection option altogether.

In the example below, the RTL layout direction is inherited from a dir attribute up in the DOM tree:

::: only-for javascript

::: example #example2 --html 1 --js 2 --ts 3

@code @code @code

:::

:::

::: only-for react

::: example #example2 :react --js 1 --ts 2

@code @code

:::

:::

::: only-for angular

::: example #example2 :angular --ts 1 --html 2

@code @code

:::

:::

::: only-for vue

::: example #example2 :vue3

@code

:::

:::

Set the layout direction to RTL

You can render Handsontable from the right to the left, regardless of your HTML document's dir attribute.

At Handsontable's initialization, add layoutDirection as a top-level grid option, and set it to 'rtl':

::: only-for javascript

::: example #example3 --js 1 --ts 2

@code @code

:::

:::

::: only-for react

::: example #example3 :react --js 1 --ts 2

@code @code

:::

:::

::: only-for angular

::: example #example3 :angular --ts 1 --html 2

@code @code

:::

:::

::: only-for vue

::: example #example3 :vue3

@code

:::

:::

Set the layout direction to LTR

You can render Handsontable from the left to the right, regardless of your HTML document's dir attribute.

At Handsontable's initialization, add layoutDirection as a top-level grid option, and set it to 'ltr':

::: only-for javascript

::: example #example4 --js 1 --ts 2

@code @code

:::

:::

::: only-for react

::: example #example4 :react --js 1 --ts 2

@code @code

:::

:::

::: only-for angular

::: example #example4 :angular --ts 1 --html 2

@code @code

:::

:::

::: only-for vue

::: example #example4 :vue3

@code

:::

:::

Set the horizontal text alignment

You can apply different horizontal text alignment settings, overwriting the horizontal text alignment resulting from your grid's layout direction.

In the example below, some columns are explicitly aligned to the left, center, or right:

::: only-for javascript

::: example #example5 --js 1 --ts 2

@code @code

:::

:::

::: only-for react

::: example #example5 :react --js 1 --ts 2

@code @code

:::

:::

::: only-for angular

::: example #example5 :angular --ts 1 --html 2

@code @code

:::

:::

::: only-for vue

::: example #example5 :vue3

@code

:::

:::

You can apply the horizontal text alignment settings to:

Related guides

<div class="boxes-list"> </div>

Related blog articles

<div class="boxes-list gray"> </div>

Configuration options

<div class="boxes-list"> </div>

Core methods

<div class="boxes-list"> </div>

Hooks

<div class="boxes-list"> </div>