change sql of autocomplete

Questionschange sql of autocomplete
Adrian Sirbu asked 3 years ago

Hi,

I need to change ( on edit form) sql of autocomplete according to a parameter.

My code:

$col = array();
$col[“title”] = “debitid”;
$col[“name”] = “debitid”;
$col[“width”] = “10”;
$col[“editable”] = true;
$col[“hidden”] = true;
$cols[] = $col;

$col = array();
$col[“title”] = “Dosar”;
$col[“name”] = “dosar_debit_more”;
//$col[“dbname”] = “dd.dosar_debit_more”;
$col[“width”] = “300”;
$col[“align”] = “left”;
$col[“formatter”] = “autocomplete”;
$col[“formatoptions”] = array(“sql”=>”SELECT id as k, dosar_debit_more as v FROM debite_dosare_view WHERE ABS(sold_ap_f)+ABS(sold_ac_f) > 0”, “search_on”=>”dosar_debit_more”, “update_field” => “debitid”, “force_select”=>true);
$col[“editable”] = true;
$col[“editrules”][“required”] = true;
$cols[] = $col;

and I want, on edit form, to force somehow a new sql forĀ  autocomplete, somethink like:

“sql”=>”SELECT id as k, dosar_debit_more as v FROM debite_dosare_view WHERE ABS(sold_ap_f)+ABS(sold_ac_f) > 0 and buget=”.$(“#buget”).val()

Thank you in advance,

Adrian

2 Answers
Abu Ghufran Staff answered 3 years ago

Hi,

You can try this:

$col["formatoptions"] = array("sql"=>"SELECT id as k, dosar_debit_more as v 
    FROM debite_dosare_view WHERE ABS(sold_ap_f)+ABS(sold_ac_f) > 0 
    AND buget={buget}",
    "search_on"=>"dosar_debit_more", 
    "update_field" => "debitid", 
    "force_select"=>true);

By this, it will replace {buget} with the value of column named ‘buget’, which is posted from clientside while sending autocomplete ajax request.

In case of further help, please share grid code and i’ll suggest the changes.

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

Hi,

Thank you!

It works but only if buget is an editable column.
Anyway, I used your solution and some triks to remove ‘buget’ column from inserted/update sql statement.

 

Thanks again!

Best regards,

 

Your Answer

8 + 4 =

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?