Filter / Search is not working for conditional data

QuestionsFilter / Search is not working for conditional data
Aamir asked 8 years ago

I have a column named problem_status and I am storing 0 and 1 value in it. I am displaying it in the grid as
if($_SESSION['userLevel'] != 'unit') {
$col = array();
$col["title"] = "Problem Status";
$col["name"] = "problem_status";
$col["condition"] = array('$row["problem_status"] == 1', 'Open', 'Closed');
$col["width"] = "110";
$col["link"] = "problem_report_sheet.php?form=problem_report&id={id}";
$col["linkoptions"] = "target='_blank' style='text-decoration: underline'";
$cols[] = $col;
} else {
$col = array();
$col["title"] = "Problem Status";
$col["name"] = "problem_status";
$open = "<a target='_blank' href='problem_report_sheet.php?form=problem_report&id={id}' style='text-decoration:underline;'>Open</a>";
$close = 'Closed';
$col["condition"] = array('$row["problem_status"] == 1', $open, $close);
$col["width"] = "110";
$cols[] = $col;
}
I have 1 and 0 value in the database but I am displaying as Open and Closed in the grid. Can you please guide why Search / Filter at the column top is not working ?

1 Answers
Abu Ghufran answered 8 years ago

For search operation, in background it uses WHERE condition of sql query. So we must have equivalent database sql for your condition.
In this case, you can set, e.g.:

$col["dbname"] = "IF(problem_status==1,'Open','Closed')";

Now your sql query will become:
SELECT field1,field2,….. from tab WHERE IF(problem_status==1,'Open','Closed') = "Open";

After that, it should give expected results.

Your Answer

3 + 19 =

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?