Date/Time Picker not Binding to Grid

4 posts, 0 answers
  1. Kong
    Kong avatar
    6 posts
    Member since:
    Feb 2017

    Posted 27 Jan 2020 Link to this post

    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?

     

     

  2. Kong
    Kong avatar
    6 posts
    Member since:
    Feb 2017

    Posted 27 Jan 2020 Link to this post

    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);
        }

  3. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1082 posts

    Posted 29 Jan 2020 Link to this post

    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.
  4. Kong
    Kong avatar
    6 posts
    Member since:
    Feb 2017

    Posted 30 Jan 2020 in reply to Alex Hajigeorgieva Link to this post

    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 ); 
        }

Back to Top