sortorder with calculation or function?

Questionssortorder with calculation or function?
Larry Groebe asked 8 years ago

I'm liking PHPGrid a whoile lot better than Koolgrid, but I've run into a stumbling block.

I have a table that needs a fixed sortorder — which involves a calculation. (specifically an enum field that I want extracted by the enum position rather than the text. You can accomplish by making it numeric in some fashion – like adding 0 or casting as integer)

But I can't get the 'sortname' parameter to accept anything other than pure field names. I think this is because you are escaping everything in quotes, and that then breaks functions, math, etc.

Even your example in forum question #1032930 fails me:

$grid["sortname"] = "FIELD(status, 'A', 'B', 'C', 'D', 'E')";
$grid["sortorder"] = "";

It throws an error. The resulting SQL in the dialog box shows all sorts of quoting:

group by s.family_id,s.student_id ORDER BY `FIELD(status, 'A', 'B', 'C', 'D', 'E')` DESC LIMIT 20 OFFSET 0

So if I wanted to sort by "status+0" or "cast(`status` as unsigned)" is there a way? Or is there a way to bypass the sortname / sortorder parameters altogether and let my query do the sorting?

2 Answers
Abu Ghufran answered 8 years ago

We have disabled it due to security reasons as it was directly passed from GET url.
We're currently working on making it functional from backend and per field basis.

Will be emailing you the update.

Abu Ghufran answered 8 years ago

With this update you can use custom sort expession with each column.

$col = array();
$col["title"] = "Gender";
$col["name"] = "gender";
$col["sortname"] = "FIELD(gender, 'Female', 'Male')"; // <=========================
$col["width"] = "30";
$col["editable"] = true;
$cols[] = $col;

Your Answer

10 + 3 =

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?