Order of an alphanumeric dropdown list in "create" modal

Order of an alphanumeric dropdown list in "create" modal

webpointzwebpointz Posts: 126Questions: 30Answers: 4
edited April 2021 in Editor

I have created a view of a table with the following query statement so that the default order of the list is properly sorted for release numbers (alphanumeric) and I'm using Editor 2.01.

    SELECT 
        `mydatabase`.`release_options` AS `optionitem`
    FROM
        `release_options`
    ORDER BY CAST(`release_options`.`releasenumber` AS UNSIGNED) DESC

Table view produces the following by default:

optionitem
13.02.020
13.01.000
13.00.040
12.00.010
11.05.000
11.05.020
11.02.010
11.04.010
11.03.010
11.03.000
11.01.000
11.04.020
10.16.000
9.00.000
9.00.030
8.12.010
5.01.020
3.08.010

But in editor, it's displaying in the dropdown list as follows:

10.16.000
11.01.000
11.02.010
11.03.000
11.03.010
11.04.010
11.04.020
11.05.000
11.05.020
12.00.010
13.00.040
13.01.000
13.02.020
3.08.010
5.01.020
8.12.010
9.00.000
9.00.030

EDITOR CODE:

// DataTables PHP library
include( "DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'mydatabase', 'id' )
    ->fields(
        Field::inst( 'mydatabase.name' ),
        Field::inst( 'mydatabase.release' )
            ->options( Options::inst()
                ->table( 'release_options' )
                ->value( 'optionitem' )
                ->label( 'optionitem' )
            )
    )
    ->leftJoin( 'release_options', 'release_options.optionitem', '=', 'mydatabase.release' )
    ->process( $_POST )
    ->json();

How can I get the list to display in the view's default order?

Answers

  • webpointzwebpointz Posts: 126Questions: 30Answers: 4

    Found the answer myself.

    added the following option to the Editor code:

    ->order('CAST(optionitem AS UNSIGNED) DESC')

This discussion has been closed.