Default values

QuestionsDefault values
Alberto asked 8 years ago

Hi! Abu.

I see this question:

https://phpgrid.desk.com/customer/portal/questions/16261098-set-default-values-with-js

But I want make "default values" the result of a sqlcommand (last record saved, for a SaveAndNext edit dialog form).

With this:
$grid["add_options"]["closeAfterAdd"] =false;

mantains opened the edit dialog.I need set the default values for a few fields of the form.

How can I do it?

Thanks.

5 Answers
Abu Ghufran answered 8 years ago

To get query data on client side is not doable now and will need manual work.
What you can do is to remove these fields from dialog and add them silently by fetching from query in callback function e.g. on_insert or on_update.

Refer demos/editing/custom-events.php for demo code.

Alberto answered 8 years ago

Hi,

Finally I decided to use variable session to determinate default values without SaveAndContinue button.

In "on_insert" and "on_update", session variables take the values:

$_SESSION["hfin"] = substr($data["params"]["t_horafin"],11,8); $_SESSION["fecha"] = substr($data["params"]["t_fecha"],8,2) . "/" . substr($data["params"]["t_fecha"],5,2) . "/" . substr($data["params"]["t_fecha"],0,4);

, and in column definition I use it:

//time column (Hour
if (isset($_SESSION["hfin"])) {
$col["editoptions"] = array("defaultValue"=>$_SESSION["hfin"]);
}else{
$col["editoptions"] = array("defaultValue"=>'00:00');
}

//date column
if (isset($_SESSION["fecha"])) {
$col["editoptions"] = array("defaultValue"=>$_SESSION["fecha_denis"]);
}

But, after insert, only refresh data on grid, default values aren't asigned to columns. Pressinf F5 to reload page, default values are applied fine. Can I force to reload it?

Thanks.

Abu Ghufran answered 8 years ago

If you want to refresh page, you can set:

$opt["onAfterSave"] = "location.reload();";
$g->set_options($opt);

Alberto answered 8 years ago

$opt["onAfterSave"] = "location.reload();";

works fine in inline editing.

I've tried:

$opt["edit_options"]["afterSubmit"] = "location.reload();";
$opt["add_options"]["afterSubmit"] = "location.reload();";

but It doesn't works.

How can I force reload page when Add/Edit dialog form is closed?

Thanks

Alberto answered 8 years ago

I have it:

$opt["edit_options"]["afterSubmit"] = "function(){location.reload(); return [true, ''];}";
$opt["add_options"]["afterSubmit"] = "function(){location.reload(); return [true, ''];}";

Your Answer

8 + 20 =

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?