Date format in a dGrid cell

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Date format in a dGrid cell

Harry Devine

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry


--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Jean-Claude Hujeux

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Harry Devine

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude <[hidden email]> wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Jean-Claude Hujeux
Well, I kind of remember struggling about this, and I guess that's why:

  •  I've extended DateTextBox to include the following custom getter, which forces the widget to return a string to renderCell (and everybody else, including the server):
        _getValueAttr: function(){
            var date = this.inherited(arguments);
            return (date ? dojo.date.stamp.toISOString(date, {selector: "date"}) : '');
        },
  • in renderCell, I have the following statement:
value = dojo.date.locale.format(dojo.date.stamp.fromISOString(value), {selector: 'date'} );
This way I ensure that wether the value comes from the server or from a modified widget, renderCell always gets it in ISO date format (I'm using ISO date format as time zone matters in my application, and ISO format is culturally neutral), and since dojo.date.locale.format expects a date object, the string needs to be converted to a date (probably the reason why you get the "_c.getDate is not a function" error message),

If a custom getter is OK in your context,  you'll have to adapt so that renderCell gets the same formatted string date from the server and from the getter: either use ISO and convert to ISO the oracle string, or convert to an oracle-compatible format in your getter,

I've made the design choice that server-side and client-side should only exchange dates in ISO format, so I do the database format (mySql in my case) to ISO format conversion on the server side,

jc

Le 20/06/2017 à 14:43, Harry Devine a écrit :

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude [hidden email] wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Harry Devine

Still not working.  Now I get "TypeError: Cannot read property 'getMonth' of null at locale.js:40 at String.replace" in my debugger.  In my PHP where I retrieve the values, I'm doing the following:


$date = strtotime($datereviewed)  // $datereviewed is in the format of "dd-MMM-yyyy", i.e. "31-MAR-17"


In my grid, I have a renderCell function as follows:


formatReviewDate: function() {

  value = locale.format(stamp.fromISOString(value), {selector: "date"});

  return value;

},


And I extended DateTextBox as follows:


define([define([

  "dojo/_base/declare",

  "dojo/date/locale",

  "dojo/date/stamp", 

  "dijit/form/DateTextBox"

], function(declare, locale, stamp, DateTextBox) {
  return declare("OracleDateTextBox", DateTextBox, {

      _getValueAttr: function() {

        var date = this.inherited(arguments);

        return (date ? stamp.toISOString(date, {selector:"date"}) : "");

      }

    });

});


I use this in my dGrid editor mixin function:

date: ({label:"Date",

              field: "date",

              renderCell: mod.formatReviewDate,

              editor: OracleDateTextBox,

              editOn: "dblclick",

              editorArgs: {style: "width:120px;", value = new Date(), constraints: {datePattern: "dd-MMM-yyyy"}},

              width: 50),


Another side effect, which may need to be another post/question, but when I edit any other field in the grid, if I press Esc to cancel the edit, the value returns to its initial value.  In the DateTextBox case, NULL gets returned.  How can I have Esc behave as the text columns in the grid?


Thanks,
Harry

On June 20, 2017 at 9:32 AM Hujeux Jean-Claude <[hidden email]> wrote:

Well, I kind of remember struggling about this, and I guess that's why:

  •  I've extended DateTextBox to include the following custom getter, which forces the widget to return a string to renderCell (and everybody else, including the server):
        _getValueAttr: function(){
            var date = this.inherited(arguments);
            return (date ? dojo.date.stamp.toISOString(date, {selector: "date"}) : '');
        },
  • in renderCell, I have the following statement:
value = dojo.date.locale.format(dojo.date.stamp.fromISOString(value), {selector: 'date'} );
This way I ensure that wether the value comes from the server or from a modified widget, renderCell always gets it in ISO date format (I'm using ISO date format as time zone matters in my application, and ISO format is culturally neutral), and since dojo.date.locale.format expects a date object, the string needs to be converted to a date (probably the reason why you get the "_c.getDate is not a function" error message),

If a custom getter is OK in your context,  you'll have to adapt so that renderCell gets the same formatted string date from the server and from the getter: either use ISO and convert to ISO the oracle string, or convert to an oracle-compatible format in your getter,

I've made the design choice that server-side and client-side should only exchange dates in ISO format, so I do the database format (mySql in my case) to ISO format conversion on the server side,

jc

Le 20/06/2017 à 14:43, Harry Devine a écrit :

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude [hidden email] wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Jean-Claude Hujeux

strtotime returns a UNIX time stamp, if that's what you send to your renderCell, it won't work. "dd-MMM-yyyy" or 31-MAR-17 won't work either. '2017-03-31' would (as it is ISO compliant). So try instead:

    gmdate('Y-m-d', strtotime($datereviewed));// I am assuming you don't need time, if that was the case, then it would be gmdate('Y-m-d\TH:i:s\Z', strtotime($datereviewed))

If you do this, you will then need to remove the datePattern in your editorArgs (and then you won't be anymore Oracle-dependent, could rename your widget to ISODateBox),

As per the ESC possible side-effect, I can't help there as I even did not know its existence :-[. Having said that, I just tried it on my application, and ... it works ! Thanks for the tip :-)! Maybe it is just a consequence of the above and will get fixed when your other pb is ?

jc
Le 20/06/2017 à 15:56, Harry Devine a écrit :

Still not working.  Now I get "TypeError: Cannot read property 'getMonth' of null at locale.js:40 at String.replace" in my debugger.  In my PHP where I retrieve the values, I'm doing the following:


$date = strtotime($datereviewed)  // $datereviewed is in the format of "dd-MMM-yyyy", i.e. "31-MAR-17"


In my grid, I have a renderCell function as follows:


formatReviewDate: function() {

  value = locale.format(stamp.fromISOString(value), {selector: "date"});

  return value;

},


And I extended DateTextBox as follows:


define([define([

  "dojo/_base/declare",

  "dojo/date/locale",

  "dojo/date/stamp", 

  "dijit/form/DateTextBox"

], function(declare, locale, stamp, DateTextBox) {
  return declare("OracleDateTextBox", DateTextBox, {

      _getValueAttr: function() {

        var date = this.inherited(arguments);

        return (date ? stamp.toISOString(date, {selector:"date"}) : "");

      }

    });

});


I use this in my dGrid editor mixin function:

date: ({label:"Date",

              field: "date",

              renderCell: mod.formatReviewDate,

              editor: OracleDateTextBox,

              editOn: "dblclick",

              editorArgs: {style: "width:120px;", value = new Date(), constraints: {datePattern: "dd-MMM-yyyy"}},

              width: 50),


Another side effect, which may need to be another post/question, but when I edit any other field in the grid, if I press Esc to cancel the edit, the value returns to its initial value.  In the DateTextBox case, NULL gets returned.  How can I have Esc behave as the text columns in the grid?


Thanks,
Harry

On June 20, 2017 at 9:32 AM Hujeux Jean-Claude [hidden email] wrote:

Well, I kind of remember struggling about this, and I guess that's why:

  •  I've extended DateTextBox to include the following custom getter, which forces the widget to return a string to renderCell (and everybody else, including the server):
        _getValueAttr: function(){
            var date = this.inherited(arguments);
            return (date ? dojo.date.stamp.toISOString(date, {selector: "date"}) : '');
        },
  • in renderCell, I have the following statement:
value = dojo.date.locale.format(dojo.date.stamp.fromISOString(value), {selector: 'date'} );
This way I ensure that wether the value comes from the server or from a modified widget, renderCell always gets it in ISO date format (I'm using ISO date format as time zone matters in my application, and ISO format is culturally neutral), and since dojo.date.locale.format expects a date object, the string needs to be converted to a date (probably the reason why you get the "_c.getDate is not a function" error message),

If a custom getter is OK in your context,  you'll have to adapt so that renderCell gets the same formatted string date from the server and from the getter: either use ISO and convert to ISO the oracle string, or convert to an oracle-compatible format in your getter,

I've made the design choice that server-side and client-side should only exchange dates in ISO format, so I do the database format (mySql in my case) to ISO format conversion on the server side,

jc

Le 20/06/2017 à 14:43, Harry Devine a écrit :

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude [hidden email] wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Harry Devine

OK, so that works very well, but with 1 exception:  when I try to write the new value back to the database, its not being accepted.  Here's what is going on, and hopefully you can spot what could be happening:


1) the grid gets filled and the date is shown as 5/22/08;

2) I double click and get the new ISODateTextBox (and the Esc works now! );

3) I select today's date as a test;

4) When I hit Enter, the dgrid-datachange event gets triggered;

5) my event handler calls my PHP script via request.post to update the database;

6) the value that is passed in for the date is 2017-06-20. 


In the database, the values are still in the format of 22-MAY-08, so I still need to put the date selected into that format for Oracle to accept it.  


Ideas?

Harry

On June 20, 2017 at 1:01 PM Hujeux Jean-Claude <[hidden email]> wrote:

strtotime returns a UNIX time stamp, if that's what you send to your renderCell, it won't work. "dd-MMM-yyyy" or 31-MAR-17 won't work either. '2017-03-31' would (as it is ISO compliant). So try instead:

    gmdate('Y-m-d', strtotime($datereviewed));// I am assuming you don't need time, if that was the case, then it would be gmdate('Y-m-d\TH:i:s\Z', strtotime($datereviewed))

If you do this, you will then need to remove the datePattern in your editorArgs (and then you won't be anymore Oracle-dependent, could rename your widget to ISODateBox),

As per the ESC possible side-effect, I can't help there as I even did not know its existence :-[. Having said that, I just tried it on my application, and ... it works ! Thanks for the tip :-)! Maybe it is just a consequence of the above and will get fixed when your other pb is ?

jc
Le 20/06/2017 à 15:56, Harry Devine a écrit :

Still not working.  Now I get "TypeError: Cannot read property 'getMonth' of null at locale.js:40 at String.replace" in my debugger.  In my PHP where I retrieve the values, I'm doing the following:


$date = strtotime($datereviewed)  // $datereviewed is in the format of "dd-MMM-yyyy", i.e. "31-MAR-17"


In my grid, I have a renderCell function as follows:


formatReviewDate: function() {

  value = locale.format(stamp.fromISOString(value), {selector: "date"});

  return value;

},


And I extended DateTextBox as follows:


define([define([

  "dojo/_base/declare",

  "dojo/date/locale",

  "dojo/date/stamp", 

  "dijit/form/DateTextBox"

], function(declare, locale, stamp, DateTextBox) {
  return declare("OracleDateTextBox", DateTextBox, {

      _getValueAttr: function() {

        var date = this.inherited(arguments);

        return (date ? stamp.toISOString(date, {selector:"date"}) : "");

      }

    });

});


I use this in my dGrid editor mixin function:

date: ({label:"Date",

              field: "date",

              renderCell: mod.formatReviewDate,

              editor: OracleDateTextBox,

              editOn: "dblclick",

              editorArgs: {style: "width:120px;", value = new Date(), constraints: {datePattern: "dd-MMM-yyyy"}},

              width: 50),


Another side effect, which may need to be another post/question, but when I edit any other field in the grid, if I press Esc to cancel the edit, the value returns to its initial value.  In the DateTextBox case, NULL gets returned.  How can I have Esc behave as the text columns in the grid?


Thanks,
Harry

On June 20, 2017 at 9:32 AM Hujeux Jean-Claude [hidden email] wrote:

Well, I kind of remember struggling about this, and I guess that's why:

  •  I've extended DateTextBox to include the following custom getter, which forces the widget to return a string to renderCell (and everybody else, including the server):
        _getValueAttr: function(){
            var date = this.inherited(arguments);
            return (date ? dojo.date.stamp.toISOString(date, {selector: "date"}) : '');
        },
  • in renderCell, I have the following statement:
value = dojo.date.locale.format(dojo.date.stamp.fromISOString(value), {selector: 'date'} );
This way I ensure that wether the value comes from the server or from a modified widget, renderCell always gets it in ISO date format (I'm using ISO date format as time zone matters in my application, and ISO format is culturally neutral), and since dojo.date.locale.format expects a date object, the string needs to be converted to a date (probably the reason why you get the "_c.getDate is not a function" error message),

If a custom getter is OK in your context,  you'll have to adapt so that renderCell gets the same formatted string date from the server and from the getter: either use ISO and convert to ISO the oracle string, or convert to an oracle-compatible format in your getter,

I've made the design choice that server-side and client-side should only exchange dates in ISO format, so I do the database format (mySql in my case) to ISO format conversion on the server side,

jc

Le 20/06/2017 à 14:43, Harry Devine a écrit :

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude [hidden email] wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Jean-Claude Hujeux

That's correct: you need to convert back on the server side from ISO format to Oracle-compatible.

With mySql and including time (my case) the statement is:

 $mySQLDate = date('Y-m-d H:i:s', strtotime($isoDate))

For Oracle looking at the php doc for the date function looks it is (but you'd better verify this):

 $oracleDate = date('d-M-y', strtotime($isoDate))

jc



Le 20/06/2017 à 20:28, Harry Devine a écrit :

OK, so that works very well, but with 1 exception:  when I try to write the new value back to the database, its not being accepted.  Here's what is going on, and hopefully you can spot what could be happening:


1) the grid gets filled and the date is shown as 5/22/08;

2) I double click and get the new ISODateTextBox (and the Esc works now! );

3) I select today's date as a test;

4) When I hit Enter, the dgrid-datachange event gets triggered;

5) my event handler calls my PHP script via request.post to update the database;

6) the value that is passed in for the date is 2017-06-20. 


In the database, the values are still in the format of 22-MAY-08, so I still need to put the date selected into that format for Oracle to accept it.  


Ideas?

Harry

On June 20, 2017 at 1:01 PM Hujeux Jean-Claude [hidden email] wrote:

strtotime returns a UNIX time stamp, if that's what you send to your renderCell, it won't work. "dd-MMM-yyyy" or 31-MAR-17 won't work either. '2017-03-31' would (as it is ISO compliant). So try instead:

    gmdate('Y-m-d', strtotime($datereviewed));// I am assuming you don't need time, if that was the case, then it would be gmdate('Y-m-d\TH:i:s\Z', strtotime($datereviewed))

If you do this, you will then need to remove the datePattern in your editorArgs (and then you won't be anymore Oracle-dependent, could rename your widget to ISODateBox),

As per the ESC possible side-effect, I can't help there as I even did not know its existence :-[. Having said that, I just tried it on my application, and ... it works ! Thanks for the tip :-)! Maybe it is just a consequence of the above and will get fixed when your other pb is ?

jc
Le 20/06/2017 à 15:56, Harry Devine a écrit :

Still not working.  Now I get "TypeError: Cannot read property 'getMonth' of null at locale.js:40 at String.replace" in my debugger.  In my PHP where I retrieve the values, I'm doing the following:


$date = strtotime($datereviewed)  // $datereviewed is in the format of "dd-MMM-yyyy", i.e. "31-MAR-17"


In my grid, I have a renderCell function as follows:


formatReviewDate: function() {

  value = locale.format(stamp.fromISOString(value), {selector: "date"});

  return value;

},


And I extended DateTextBox as follows:


define([define([

  "dojo/_base/declare",

  "dojo/date/locale",

  "dojo/date/stamp", 

  "dijit/form/DateTextBox"

], function(declare, locale, stamp, DateTextBox) {
  return declare("OracleDateTextBox", DateTextBox, {

      _getValueAttr: function() {

        var date = this.inherited(arguments);

        return (date ? stamp.toISOString(date, {selector:"date"}) : "");

      }

    });

});


I use this in my dGrid editor mixin function:

date: ({label:"Date",

              field: "date",

              renderCell: mod.formatReviewDate,

              editor: OracleDateTextBox,

              editOn: "dblclick",

              editorArgs: {style: "width:120px;", value = new Date(), constraints: {datePattern: "dd-MMM-yyyy"}},

              width: 50),


Another side effect, which may need to be another post/question, but when I edit any other field in the grid, if I press Esc to cancel the edit, the value returns to its initial value.  In the DateTextBox case, NULL gets returned.  How can I have Esc behave as the text columns in the grid?


Thanks,
Harry

On June 20, 2017 at 9:32 AM Hujeux Jean-Claude [hidden email] wrote:

Well, I kind of remember struggling about this, and I guess that's why:

  •  I've extended DateTextBox to include the following custom getter, which forces the widget to return a string to renderCell (and everybody else, including the server):
        _getValueAttr: function(){
            var date = this.inherited(arguments);
            return (date ? dojo.date.stamp.toISOString(date, {selector: "date"}) : '');
        },
  • in renderCell, I have the following statement:
value = dojo.date.locale.format(dojo.date.stamp.fromISOString(value), {selector: 'date'} );
This way I ensure that wether the value comes from the server or from a modified widget, renderCell always gets it in ISO date format (I'm using ISO date format as time zone matters in my application, and ISO format is culturally neutral), and since dojo.date.locale.format expects a date object, the string needs to be converted to a date (probably the reason why you get the "_c.getDate is not a function" error message),

If a custom getter is OK in your context,  you'll have to adapt so that renderCell gets the same formatted string date from the server and from the getter: either use ISO and convert to ISO the oracle string, or convert to an oracle-compatible format in your getter,

I've made the design choice that server-side and client-side should only exchange dates in ISO format, so I do the database format (mySql in my case) to ISO format conversion on the server side,

jc

Le 20/06/2017 à 14:43, Harry Devine a écrit :

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude [hidden email] wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date format in a dGrid cell

Harry Devine

That's what I figured.  I was able to get it to work as follows:

$date = date_create_from_format("Y-n-j", $value);

$value = date_format($date, "d-M-y");


Worked like a charm.  Thank you VERY MUCH for all of your help on this.  Looks like I now owe you 2! :-)


Thanks,

Harry

On June 20, 2017 at 5:02 PM Hujeux Jean-Claude <[hidden email]> wrote:

That's correct: you need to convert back on the server side from ISO format to Oracle-compatible.

With mySql and including time (my case) the statement is:

 $mySQLDate = date('Y-m-d H:i:s', strtotime($isoDate))

For Oracle looking at the php doc for the date function looks it is (but you'd better verify this):

 $oracleDate = date('d-M-y', strtotime($isoDate))

jc



Le 20/06/2017 à 20:28, Harry Devine a écrit :

OK, so that works very well, but with 1 exception:  when I try to write the new value back to the database, its not being accepted.  Here's what is going on, and hopefully you can spot what could be happening:


1) the grid gets filled and the date is shown as 5/22/08;

2) I double click and get the new ISODateTextBox (and the Esc works now! );

3) I select today's date as a test;

4) When I hit Enter, the dgrid-datachange event gets triggered;

5) my event handler calls my PHP script via request.post to update the database;

6) the value that is passed in for the date is 2017-06-20. 


In the database, the values are still in the format of 22-MAY-08, so I still need to put the date selected into that format for Oracle to accept it.  


Ideas?

Harry

On June 20, 2017 at 1:01 PM Hujeux Jean-Claude [hidden email] wrote:

strtotime returns a UNIX time stamp, if that's what you send to your renderCell, it won't work. "dd-MMM-yyyy" or 31-MAR-17 won't work either. '2017-03-31' would (as it is ISO compliant). So try instead:

    gmdate('Y-m-d', strtotime($datereviewed));// I am assuming you don't need time, if that was the case, then it would be gmdate('Y-m-d\TH:i:s\Z', strtotime($datereviewed))

If you do this, you will then need to remove the datePattern in your editorArgs (and then you won't be anymore Oracle-dependent, could rename your widget to ISODateBox),

As per the ESC possible side-effect, I can't help there as I even did not know its existence :-[. Having said that, I just tried it on my application, and ... it works ! Thanks for the tip :-)! Maybe it is just a consequence of the above and will get fixed when your other pb is ?

jc
Le 20/06/2017 à 15:56, Harry Devine a écrit :

Still not working.  Now I get "TypeError: Cannot read property 'getMonth' of null at locale.js:40 at String.replace" in my debugger.  In my PHP where I retrieve the values, I'm doing the following:


$date = strtotime($datereviewed)  // $datereviewed is in the format of "dd-MMM-yyyy", i.e. "31-MAR-17"


In my grid, I have a renderCell function as follows:


formatReviewDate: function() {

  value = locale.format(stamp.fromISOString(value), {selector: "date"});

  return value;

},


And I extended DateTextBox as follows:


define([define([

  "dojo/_base/declare",

  "dojo/date/locale",

  "dojo/date/stamp", 

  "dijit/form/DateTextBox"

], function(declare, locale, stamp, DateTextBox) {
  return declare("OracleDateTextBox", DateTextBox, {

      _getValueAttr: function() {

        var date = this.inherited(arguments);

        return (date ? stamp.toISOString(date, {selector:"date"}) : "");

      }

    });

});


I use this in my dGrid editor mixin function:

date: ({label:"Date",

              field: "date",

              renderCell: mod.formatReviewDate,

              editor: OracleDateTextBox,

              editOn: "dblclick",

              editorArgs: {style: "width:120px;", value = new Date(), constraints: {datePattern: "dd-MMM-yyyy"}},

              width: 50),


Another side effect, which may need to be another post/question, but when I edit any other field in the grid, if I press Esc to cancel the edit, the value returns to its initial value.  In the DateTextBox case, NULL gets returned.  How can I have Esc behave as the text columns in the grid?


Thanks,
Harry

On June 20, 2017 at 9:32 AM Hujeux Jean-Claude [hidden email] wrote:

Well, I kind of remember struggling about this, and I guess that's why:

  •  I've extended DateTextBox to include the following custom getter, which forces the widget to return a string to renderCell (and everybody else, including the server):
        _getValueAttr: function(){
            var date = this.inherited(arguments);
            return (date ? dojo.date.stamp.toISOString(date, {selector: "date"}) : '');
        },
  • in renderCell, I have the following statement:
value = dojo.date.locale.format(dojo.date.stamp.fromISOString(value), {selector: 'date'} );
This way I ensure that wether the value comes from the server or from a modified widget, renderCell always gets it in ISO date format (I'm using ISO date format as time zone matters in my application, and ISO format is culturally neutral), and since dojo.date.locale.format expects a date object, the string needs to be converted to a date (probably the reason why you get the "_c.getDate is not a function" error message),

If a custom getter is OK in your context,  you'll have to adapt so that renderCell gets the same formatted string date from the server and from the getter: either use ISO and convert to ISO the oracle string, or convert to an oracle-compatible format in your getter,

I've made the design choice that server-side and client-side should only exchange dates in ISO format, so I do the database format (mySql in my case) to ISO format conversion on the server side,

jc

Le 20/06/2017 à 14:43, Harry Devine a écrit :

I've done this before, but in this case, it doesn't work.  The date is coming from an Oracle database, and is already in the "dd-MMM-yyyy" format (i.e. 20-JUN-17).  The issue I have is AFTER I do an edit in the Grid.  Is there a way that I can use renderCell ONLY after a grid cell edit?  At the moment, since the original date value is already in that format, I'm getting "_c.getDate is not a function" in the debugger on the following line in my renderCell function:  locale.format(object.date, {selector: "date", datePattern: "dd-MMM-yyyy"});


Any ideas?

Harry

On June 19, 2017 at 5:02 PM Hujeux Jean-Claude [hidden email] wrote:

I do this type of formatting in the renderCell function for the column, using dojo.date.locale.format,

jc


Le 19/06/2017 à 20:15, Harry Devine a écrit :

I have a dGrid that I have added the Editor mixin to.  In this column, the data is formatted as follows: dd-MMM-yyy (i.e. "31-MAR-17".  When I double click on that column, I get a DateTextBox.  However, when I pick the date, the value that gets put into the column is in this format:  Mon Jun 19 2017 00:00:00 GMT-0400 (Eastern Daylight Time).  How can I format it to show 19-JUN-17?  I tried to change evt.value to the formatted value, but it doesn't seem to change it.


Thanks,

Harry





 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest




 

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

--
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/

[hidden email]
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Loading...