I have tried to sort column with numbers using:
$col[“sorttype”] = number;
but it doesn’t work.
Can you help me?
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)”;
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)”;
This will need debugging your select query. For that follow these steps:
- Load datagrid normal way.
- Goto grid code and after creating $g (grid) object, add $g->debug_sql = true;
- 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.
Perhaps you are using older version. You can email me your order number for update process.
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?
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?