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.
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