Sorting numbers problem

QuestionsSorting numbers problem
Mox asked 4 years ago

I have tried to sort column with numbers using:

$col[“sorttype”] = number;

but it doesn’t work.

Can you help me?

7 Answers
Abu Ghufran Staff answered 4 years ago

If you’re using array based grid then above would work. If using server side grid then you must cast the column to integer for SQL ORDER BY integer sorting clause. e.g. if you field is ‘age’

$col[“name”] = “age”;
$col[“sortname”] = “cast(age as unsigned)”;

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Mox answered 4 years ago

That works, thank you.

I still have problem for numeric search. In search records when I specify bigger then 2500, it doesn’t filter >2500. It gives me some strange results. Column is:

$col[“formatter”] = “number”;
$col[“formatoptions”] = array(“thousandsSeparator” => “.”,
“decimalSeparator” => “,”,
“decimalPlaces” => 2);
$col[“align”] = “right”;
$col[“sorttype”] = “number”;
$col[“sortname”] = “CAST(price as NUMERIC)”;

Abu Ghufran Staff answered 4 years ago

This will need debugging your select query. For that follow these steps:

  1. Load datagrid normal way.
  2. Goto grid code and after creating $g (grid) object, add $g->debug_sql = true;
  3. Perform autofilter search, it will push the exact query as error message.

PS: $col[“sorttype”] = “number”; is only applicable on array based grid. You can safely remove it.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Mox answered 4 years ago

I added debug_sql=true but I don’t see any error message.

Abu Ghufran Staff answered 4 years ago

Perhaps you are using older version. You can email me your order number for update process.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Mox answered 4 years ago

I downloaded few days ago free version.

Mox answered 4 years ago

IĀ  have managed to get debugĀ  working, and I see that query used for search price > 2555 is

SELECT id, price FROM prices WHERE 1=1 AND price > 2555

Price should be casted in search, it needs to be like this:

SELECT id, price FROM prices WHERE 1=1 AND CAST(price AS NUMERIC) > 2555

How to do that?

Your Answer

14 + 9 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?