Issue handling LOV sorting for lookup field
Posted: 2024-08-18 14:41
Appgini 24.17
I have a lookup field, and my SQL statement is like this:
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
I don't want the LOV to be sorted.
When putting the above in the advanced lookup option, the LOV in the drop-down will be sorted by title by itself, which is not what I want.
When I changed the SQL statement to below to force it sorted by id (which is equivalent to unsorted):
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
ORDER BY 1
the drop-down now becomes empty, with a message "No matches found!".
When I changed the SQL statement to the following:
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
ORDER BY 2
again, the drop-down becomes empty, with a message "No matches found!".
and if I put a semicolon to terminate the statement, like this:
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
ORDER BY 1;
again, the drop-down becomes empty, with a message "No matches found!".
From the above observation, I suspect the bug is, as long as there is ORDER BY in the statement in advanced lookup option, it will cause the LOV to be empty.
And if we don't put any ORDER BY in the statement, it will work, but the list is not unsorted (or sorted by id number). It will somehow sorted by other field, which sometimes is not what we want.
I have a lookup field, and my SQL statement is like this:
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
I don't want the LOV to be sorted.
When putting the above in the advanced lookup option, the LOV in the drop-down will be sorted by title by itself, which is not what I want.
When I changed the SQL statement to below to force it sorted by id (which is equivalent to unsorted):
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
ORDER BY 1
the drop-down now becomes empty, with a message "No matches found!".
When I changed the SQL statement to the following:
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
ORDER BY 2
again, the drop-down becomes empty, with a message "No matches found!".
and if I put a semicolon to terminate the statement, like this:
SELECT `m_title`.`id`, `m_title`.`title` FROM `m_title`
WHERE `m_title`.`is_t1`=1 AND `m_title`.`is_active`=1
ORDER BY 1;
again, the drop-down becomes empty, with a message "No matches found!".
From the above observation, I suspect the bug is, as long as there is ORDER BY in the statement in advanced lookup option, it will cause the LOV to be empty.
And if we don't put any ORDER BY in the statement, it will work, but the list is not unsorted (or sorted by id number). It will somehow sorted by other field, which sometimes is not what we want.