Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Cms 2.1.4 Update released for Drupal core (2.1.4)! Release: Drupal 12.0.0-alpha1 First alpha version released for Drupal core (12.0.0-alpha1). Release: PhotoSwipe - Responsive JavaScript Modal Image Gallery 5.0.9 Minor update available for module photoswipe (5.0.9). Release: AI (Artificial Intelligence) 1.4.8 Minor update available for module ai (1.4.8). Release: AI (Artificial Intelligence) 1.3.13 Minor update available for module ai (1.3.13). Release: Moderated Content Bulk Publish 2.0.53 Minor update available for module moderated_content_bulk_publish (2.0.53). Release: Mailchimp 2.2.9 Minor update available for module mailchimp (2.2.9). Release: Mailchimp 3.1.4 Minor update available for module mailchimp (3.1.4). Module Revived: Image field to media 3.0.2 Module image_field_to_media updated after 13 months of inactivity (3.0.2). Security Coverage: Analyze PostHog Module analyze_posthog now has official Drupal security advisory coverage.

Views Cast Sort

No security coverage

Part of the Views ecosystem · 207 projects

View on drupal.org

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.

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
4 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

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