Undefined NaN when selecting custom month year select

QuestionsUndefined NaN when selecting custom month year select
Mario Verleene asked 3 weeks ago

I’m getting Undefined NaN when selecting “some” custom month year :

This is de code :

$col = array();
$col[“title”] = “Pmaand”;
$col[“name”] = “planningmaand”;
$col[“tooltip”] = “Planningsmaand”;
$col[“width”] = “4”;
$col[“align”] = “left”;
$col[“editable”] = true;
$col[“edittype”] = “select”;

$str = $grid->get_dropdown_values(“SELECT planningmaand as k, CONCAT(monthname(planningmaand),’ ‘,YEAR(planningmaand)) as v FROM XXL_2020Y where planningmaand<>’0000-00-00’ group by planningmaand”);

$col[“searchoptions”] = array(“value”=>$str);
$col[“stype”] = “select-multiple”;
$col[“searchoptions”][“value”] = $str;
$col[“formatter”] = “date”;

$str = “”;

$start = strtotime(‘2020-08-01’);
$end = strtotime(‘2021-12-01’);
$range = array(date(‘Y-m-d’, $start) => date(‘Y-m-d’, $start));
while ( $start <= strtotime(‘-1 month’, $end) ) {
$start = strtotime(‘+1 month’, $start);
$yearMonth = date(‘Y-m-d’, $start);
$full = date(‘M Y’,$start);
$range[$yearMonth] = $yearMonth;
$str .= $yearMonth.’:’.$full.’;’;
}

$col[“editoptions”] = array(“style”=>”width:200px”,”value”=>$str);
$col[“formatoptions”] = array(“srcformat”=>’Y-m-d’,”newformat”=>’M Y’,”dateformat”=>’Y-m-d’, “opts” => array(“changeYear” => true, “changeMonth” => true, “dateFormat”=>’yy-mm-dd’, “minDate”=>”2020.09.01”));
$col[“hidden”] = false;
$cols[] = $col;

This is the html code :

<select role=”select” style=”width: 109px !important;” id=”1_planningmaand” name=”planningmaand” rowid=”1″ size=”1″ class=”editable” autocomplete=”off”><option role=”option” value=”2020-09-01″>Sep 2020</option><option role=”option” value=”2020-10-01″>Oct 2020</option><option role=”option” value=”2020-11-01″>Nov 2020</option><option role=”option” value=”2020-12-01″>Dec 2020</option><option role=”option” value=”2021-01-01″>Jan 2021</option><option role=”option” value=”2021-02-01″>Feb 2021</option><option role=”option” value=”2021-03-01″>Mar 2021</option><option role=”option” value=”2021-04-01″>Apr 2021</option><option role=”option” value=”2021-05-01″>May 2021</option><option role=”option” value=”2021-06-01″>Jun 2021</option><option role=”option” value=”2021-07-01″>Jul 2021</option><option role=”option” value=”2021-08-01″>Aug 2021</option><option role=”option” value=”2021-09-01″>Sep 2021</option><option role=”option” value=”2021-10-01″>Oct 2021</option><option role=”option” value=”2021-11-01″>Nov 2021</option><option role=”option” value=”2021-12-01″>Dec 2021</option><option role=”option” value=””>undefined</option></select>

This works and writes the dates perfectly to mysql database but gives on grid it gives undefined NaN on :

March 2021

May 2021

October 2021

when saving. When refreshing the grid I can see the actual dates like : March 2021, May 2021, October 2021.

Why these only give NaN (Not a Number)?

Is there a workaround so that the “error” undefined NaN doesn’t get displayed but like the others show the actual selected date?

what am I doing wrong?

 

2 Answers
Abu Ghufran Staff answered 3 weeks ago

I’ll regenerate this case and update you back.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Mario Verleene answered 3 weeks ago

UPDATE :

I changed my code to reflect the language I use (Dutch) and hardcoded the months into the script :

It solves the issue for March & May but still gives the error Undefined NaN for selecting October (regardless the year). What was strange when I didn’t use format options something strange happend to the date… Normally this is 10/01/2020 (mm/dd/yyyy) it changed it to 01/01/2020 why remains a mistery to me.

$col = array();
$col[“title”] = “Pmaand”;
$col[“name”] = “planningmaand”;
$col[“tooltip”] = “Planningsmaand”;
$col[“width”] = “4”;
$col[“align”] = “left”;
$col[“editable”] = true;
$col[“edittype”] = “select”;

$str = $grid->get_dropdown_values(“SELECT planningmaand as k, CONCAT(monthname(planningmaand),’ ‘,YEAR(planningmaand)) as v FROM XXL_2020Y where planningmaand<>’0000-00-00’ group by planningmaand”);

$col[“searchoptions”] = array(“value”=>”:;”.$str);
$col[“stype”] = “select-multiple”;
$col[“searchoptions”][“value”] = “:;”.$str;
$col[“formatter”] = “date”;

$str = “”;

$start = strtotime(‘8/1/2020′);
$end = strtotime(’12/1/2021’);
$range = array(date(‘m/d/Y’, $start) => date(‘m/d/Y’, $end));
$MSNames= [“Jan”, “Feb”, “Maa”, “Apr”, “Mei”, “Jun”, “Jul”, “Aug”, “Sep”, “Okt”, “Nov”, “Dec”];
$MFNames= [“Januari”, “Februari”, “Maart”, “April”, “Mei”, “Juni”, “Juli”, “Augustus”, “September”, “Oktober”, “November”, “December”];

while ( $start <= strtotime(‘-1 month’, $end) ) {
$start = strtotime(‘+1 month’, $start);
$yearMonth = date(‘m/d/Y’, $start);
$cmonth = date(‘n’,$start)-1;
$cyear = date(‘Y’,$start);
$full = $MSNames[$cmonth].’ ‘.$cyear;
$range[$yearMonth] = $yearMonth;
$str .= $yearMonth.’:’.$full.’;’;
}
$str2 = substr($str, 0, -1);

$col[“editoptions”] = array(“style”=>”width:200px”,”value”=>”:;”.$str2);
$col[“formatoptions”] = array(“srcformat”=>’Y-m-d’,”newformat”=>’M Y’);
$col[“hidden”] = false;
//$col[“datefmt”] = “m-Y”;
//$col[“searchoptions”][“sopt”] = array(“cn”);
$cols[] = $col;

Hope this helps solve the “language” / date issue? just that selecting oktober does not work… 🙁

But when I refresh shows the correct selected date. Like Okt 2020 or Okt 2021

Best regards

Your Answer

19 + 3 =

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?