Support > Repository > Model > Sort

Specify the initial sort rule of the search result list.

Figure 1 shows an example in which three items of "name", "name" and "e-mail" are specified as sort keys on the customer model list display screen.

When displaying the screen, arrange by the first sort key.(In this example, it is in alphabetical descending order.)

Figure 1 List display screen with sort key specified

Items specified as sort keys can be clicked on the item name part.Click to sort by that item.Click on the same item to reverse the sort order.

Figure 2 shows an example of switching email items to alphabetical ascending sort.

Figure 2 Switch to ascending sort of e-mail items

The sort key is memorized

The sort key is memorized for each screen and for each user.When you finish using it and logging on again, the list screen sorted by the last specified sort key is displayed.

Initialize sort key

When "Clear search condition" is done on the search screen, it returns to the initial sort order at the same time as re-search.

Figure 3 shows the definition of the customer model used in the sample.Here, we will set the sort key for the three items "name" "name" and "e-mail".

Figure 3 Definition of customer model

Open the model item detail definition.In the column "sort order" of each itemA numberSpecify.It is allocated as first sort key, second sort key ... in ascending order of numbers.(FIG. 4, FIG. 5, FIG. 6)

If "Minus" is specified before the numerical value, the initial sort rule will be reverse sorted.("E-mail" item in FIG. 4)

Figure 4 "E-mail" item is the first sort key and reverse order
Figure 5 "Name" is the second sort key
Fig. 6 Set the "Name" item as the third sort key

Sorting is realized by SQL processing (ORDER BY clause) of the database. Therefore, rules change depending on the database.

Items not saved in the database can not be specified as sort keys

Sorting is realized by the ORDER BY clause of the database.Therefore, items not to be stored in the database can not be specified as a sort key.

General rules

  • Numeric and date types are in ascending order.
  • About the alphabet, A, B, C ... in order.
  • For Japanese characters, the order of character codes that created the database.(For details on how to check and define character codes, please check the database documentation.)
Sorting by Japanese characters may not be the sequence expected by the user.This is because it is not a cultural list but a character code order.

Sort NULL values

Sorting with a value of "NULL" is handled differently by the database.

  • In SQL Server, MySQL, it is treated as the smallest value.
  • In Oracle, DB2, PostgreSQL, it is treated as the largest value.(In Oralce 9i and later, you can also specify handling of NULL.)
  • In the internal database (HSQLDB), it is not subject to sorting.The line containing NULL is always at the beginning.

Sort model reference items

It is deprecated to sort model reference items.

The reason is that model reference items are sorted by "ID value".In many cases, you will get the impression that the displayed contents and the sort order do not match.

Model Reference (Reference Linking) Item Sort

Reference linked itemSave your modelIt is necessary to be.

Display of child model part in foreign key relation

Main key handling

The primary key is always included in the sort key.

In order to realize the pagination function, you need to specify the primary key in the order by clause.