This is a migrated thread and some comments may be shown as answers.

Date/Time Picker not Binding to Grid

3 Answers 25 Views
This is a migrated thread and some comments may be shown as answers.
Kong
Top achievements
Rank 1
Kong asked on 27 Jan 2020, 05:58 PM

I have a date/time picker in a popup editor that I use javascript to set a default date when the editor opens.  The javascript is able to change the value of the date/time picker but the value is not binding to the grid, hence not saving to the server.  The record saved will show null for the date field. 

 

How do I set a default date to a date/time picker via javascript and have it bind to the record upon saving?

 

 

3 Answers, 1 is accepted

Sort by
0
Kong
Top achievements
Rank 1
answered on 27 Jan 2020, 10:20 PM

I found the answer after doing a bit of digging. (see below)  This is the function that is called when a grid record is edited.

 

function onEdit(e) {
             var today = "1/26/2020";
            e.model.set('DateField', today);
    }

0
Alex Hajigeorgieva
Telerik team
answered on 29 Jan 2020, 10:34 AM

Hello, Kong,

There default value for date types is infact today's date and time:

https://dojo.telerik.com/@bubblemaster/OTAXowOW/2

If in your project this does not occur, then perhaps the field is not a date type. You can confirm the schema is serialized as expected by checking the script in the generated HTML as demonstrated in this forum post:

https://www.telerik.com/forums/jquery-grid-not-loading-data-even-though-json-is-returned#cyGhfScwlkCoxshn8cHGWQ

Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
0
Kong
Top achievements
Rank 1
answered on 30 Jan 2020, 07:31 PM

Thank you Alex.  I had a requirement to automatically set the date field to something other than the current date.  I was able to accomplish this through utilizing the Edit event from the grid.

 

//For example:

.Events(e => e.Edit("onEdit"))

 

//Here's the javascript function that is called when the popup editor launches.

function onEdit(e) {
             var someDate = "1/26/2020";
            e.model.set('DateField', someDate ); 
    }

Tags
Grid
Asked by
Kong
Top achievements
Rank 1
Answers by
Kong
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or