defaultValue = another column?

QuestionsdefaultValue = another column?
Tim Moore asked 6 years ago

Is there an easy way to make the defaultValue of a column equal the results of another column or query?

$g->select_command = “SELECT * FROM tbl_job
INNER JOIN
(SELECT (MAX(job_number) + 1) AS max_job
FROM tbl_job) top_job
LEFT JOIN tbl_customer ON customer_id = fk_customer
LEFT JOIN tbl_proj_man ON fk_proj_id = proj_id
“;

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

$col = array();
$col[“title”] = “Job Number”;
$col[“name”] = “job_number”;
$col[“link”] = “addunit.php?job={job_id}”;
$col[“width”] = “50”;
$col[“hidden”] = false;
$col[“editable”] = true;
$col[“editrules”] = array(“required”=>true, “number”=>true, “minValue”=>1000, “maxValue”=>9999);
$col[“editoptions”][“defaultValue”] = “{max_job}”
$cols[] = $col;

I simply want to find the next job_number in the DB and make it the default value in the col job_number. Thanks in advance.

2 Answers
Abu Ghufran Staff answered 6 years ago

Hello, The default value may not work in your case as it is only set for the first time and you will need latest job-id every time you open add form.

So, alternate solution would be to call an ajax request which returns job-id and set it in your job-number field.

For demo, refer this code: https://gist.github.com/gridphp/27e1f4b009e2a838be0bfc49d66e0d0f

See line 25,35,63

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Tim answered 6 years ago

Abu, thanks again. works perfectly!

Your Answer

8 + 16 =

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?