In-line serach with checkbox

QuestionsIn-line serach with checkbox
Massimo Gagliardi asked 11 years ago

Hi Abu
I have this column definition:

$col = array();
$col["title"] = "AF";
$col["name"] = "FlagFornitore";
$col["align"] = "center";
$col["width"] = "5";
$col["editable"] = true;
$col["edittype"] = "checkbox";
$col["editoptions"] = array("size"=>$col["width"], "value"=>"SI:NO");
$col["condition"] = array('$row["FlagFornitore"] == 1', 'SI', 'NO');
$col["export"] = true;
$cols[] = $col;

In the grid you can view 'SI' or 'NO' instead of '1' or '0';
In edit or add mode you can check or uncheck the field and with this code in custom add and edit routines:

if ($data["params"]["FlagFornitore"] == 'SI')
$data["params"]["FlagFornitore"] = 1;
else
$data["params"]["FlagFornitore"] = 0;

you can re-obtain the correct values ('0' or ''1) in the database.

But in the in-line search you have to write '0' or '1' because if you write 'SI' or 'NO' you don't obtain anything.
Is there a solution for this case?
Is it possible to write 'SI' or 'NO' and obtain the only rows that have '1' or '0' in the column?
Thanks in advance

4 Answers
Abu Ghufran answered 11 years ago

Try setting dbname param, as it is repalced in WHERE clause.

$col["dbname"] = "IF(FlagFornitore = 1, 'SI','NO)";

Pavel answered 10 years ago

Hi,
I have the same problem. I'm using MSSQL 2008 R2.

$col_obj = array();
$col_obj["title"] = "Dodáno";
$col_obj["name"] = "BDodano";
$col_obj["condition"] = array('$row["BDodano"]==1','Ano','Ne');
$col_obj["align"] = "center";
$col_obj["dbname"] = "IF(BDodano = 1; 'Ano';'Ne')";
$cols_obj[] = $col_obj;

When I try to put A in search box I see this error "Couldn't execute query. SQLState: 42000 Error Code: 156 Message: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'IF'. SQLState: 42000 Error Code: 102 Message: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ','. – SELECT count(*) as c FROM (SELECT ID,DatOd,DatDo,Cislo,Firma,Jmeno,KcCelkem,Vyrizeno,BDodano,stredisko,cinnost FROM appobj.V_OBJ where RelTpObj = 1 AND IF(BDodano = 1, 'Ano','Ne') LIKE N'%A%') pg_tmp"

Pavel answered 10 years ago

I solved this problem as :

$col_obj = array();
$col_obj["title"] = "Dodáno"; // caption of column
$col_obj["name"] = "BDodano"; // grid column name, same as db field or alias from sql
$col_obj["condition"] = array('$row["BDodano"]==1','Ano','Ne');
$col_obj["align"] = "center";
$col_obj["dbname"] = "case when BDodano > 0 then 'Ano' else 'Ne' END";
$cols_obj[] = $col_obj;

Abu Ghufran answered 10 years ago

Thanks for sharing.

Your Answer

18 + 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?