Hi,
I've got a date type column and would like to display today's date as default value when opening the edit dialog.
Displaying the column value in the grid*, it should be empty.
If I use col["default"], the grid shows today's date for that column, and don't want that. It has to be displayed only as a suggested value on the edit dialog only.
Any help? Thanks.
* Full version.
You can use:
$col["editoptions"]["value"] = date("Y-m-d"); // or any other date format.
When you click on calendar icon next to date field, it shows current date focused.
Thanks for your reply Abu.
You said "When you click on calendar icon" – it works, but that's not what I want.
I would like to set the date when you open the edit dialog (the date is already displayed on the edit dialog) – which means the user does not need to click on the calendar icon if he wants todays date (as it is already filled in).
Is there any work around for this?
Thanks.
When you edit a record, the previous value saved in database is auto filled in field.
Do you want to ignore the old db value and prefill with current date?
$opt["edit_options"]["afterShowForm"] = 'function () { $("#invdate").val("'.date("Y-m-d").'"); }';
$g->set_options($opt);
// where invdate is field name.
If you want to set it while adding record,
$col["editoptions"]["defaultValue"] = date("Y-m-d");
The defaultValue date format and the formatoptions["newformat"] date format must be same to fill field.
Yes, that's exactly what I want.
We are almost there.
It works if the edit mode is a dialog via double click.
If it is in inline edit mode, it does not show the date pre filled.
if other words, if I add this script below, works.
if I remove this script, it doesn't.
<script>
var opts = {
'ondblClickRow': function (id) {
jQuery(this).jqGrid('editGridRow', id, <?php echo json_encode_jsfunc($g->options["edit_options"])?>);
}
};
</script>
Thanks for assisting me again.
Currently it is not doable in inline edit mode.
It will require some core lib changes.