Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Views Cast Sort

No security coverage Under active development

Part of the Views ecosystem · 281 projects

This module improves sorting in Drupal Views for string fields containing numbers. It allows users to sort these fields numerically instead of alphabetically by applying SQL type casting or by extracting trailing numbers before sorting, offering a lighter alternative to modules that use pre-computed index tables.

The problem

Drupal Views sorts string fields alphabetically by default. When those strings contain numbers the result looks wrong:

  • Product 1
  • Product 10
  • Product 101
  • Product 15
  • Product 2

This module fixes that by applying SQL type casting directly in the ORDER BY clause; no pre-computed index tables, no custom SQL required from site builders.

Two sort handlers

Cast sort wraps the field in CAST(field AS type) before sorting. Use this for fields that store purely numeric values as strings: SKUs, reference numbers, serial numbers, rankings. Supports integer, decimal, date, datetime, and text cast types, configurable in the Views UI.

Trailing integer sort uses REGEXP_SUBSTR(field, '[0-9]+$') to extract the integer at the end of each value before casting. Use this for mixed strings such as "Product 10", "SKU-ref-207", or "Item 3B".

Requirements

Drupal 10 or 11
Trailing integer sort requires MySQL 8.0.4+ or MariaDB 10.0.5+. Cast sort works on all supported Drupal databases. An in-form warning and watchdog entry are shown if the database does not meet the requirement.
Relation to similar modules

Views Natural Sort solves a related problem using a pre-computed index approach. Views Cast Sort is a lighter alternative for the common case where you want numeric ordering of a string field without maintaining a separate index.

Ask your assistant about Views Cast Sort

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Apr 2026
Latest release
5 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core PHP Release date
1.0.x-dev Dev 10–11 Apr 20, 2026