How can i flag a boolean variable to the kendo ui datetimepicker on grid pageload?

5 posts, 1 answers
  1. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    38 posts
    Member since:
    Mar 2008

    Posted 14 Jun Link to this post

    Hi guys, basically i have mvc kendo ui application. where i have two kendo ui datetimepicker wrappers. What i want to do is on pageload of the grid i would like to flag boolean variable with "true". if true value means its on pageload. So based on the true value i do something like this on the date filters below...

    public JsonResult GetIncidents([DataSourceRequest]DataSourceRequest request, int? AccountID, int? SiteID, int? StatusID, int? AuditID, DateTime DateFrom, DateTime EndDate, bool isPageLoaded)
          {
              
              
               
     
              using (var db = new IntelligentThinkingACSAEntities())
              {
                  DateTime startDate = DateTime.Now;
                  if (isPageLoaded)
                  {
                      startDate = DateFrom.AddDays(-10);
                       
                    
                      //  DateTime endDate = DateTo.AddDays(-10);
                  }
                  else
                  {
                      startDate = DateFrom;
                  }

    if its not pageload it will not filter data based on the ten days back date

    im passing parametes like these below...

    function IncidentsFilter() {
             
     
             return {
                 AccountID: $("#KAirports").val() === "" ? 0 : $("#KAirports").val(),
                 SiteID: $("#KSite").val() === "" ? 0 : $("#KSite").val(),
                 StatusID: $("#KStatusFilter").val() === "" ? 0 : $("#KStatusFilter").val(),
                 AuditID:  $("#KAuditS").val() === "" ? 0 : $("#KAuditS").val(),
                 DateFrom: $("#KDateFrom").val() === "" ? new Date : $("#KDateFrom").val(),
                 EndDate: $("#KDateTo").val() === "" ? new Date : $("#KDateTo").val(),
                 isPageLoaded: true
                
     
                 
             };
         }

     

    Please help guys, Im stuck

  2. Slav
    Admin
    Slav avatar
    1355 posts

    Posted 16 Jun Link to this post

    Hi Marc,

    I checked the provided information, however I am still not sure about the scenario at hand. If I understand correctly, you want to set the start date of the DateTimePicker based on a flag (isPageLoaded), which is set at some point. What is not clear to me is when this flag should be set.

    Could you please send a fully runnable sample that shows how you currently pass the dates to the DateTimePicker via the code snippets below (excluding the isPageLoaded parameter), as well as information on which event should the parameter be set? This will allow me to get a better understanding of the scenario and suggest a solution.

    Regards,
    Slav
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    38 posts
    Member since:
    Mar 2008

    Posted 16 Jun Link to this post

    Hi Slav, Thanks for the reply...

    just to makes things clear, I have a grid which when it loads(on pageload first time) it uses the current dates from the datetimepicker to filter the data based on the default datetime set on the datetimepicker ui control.What i want to achieve is to minus 10 days when the grid loads first time...But if its not loading for the first time it allows the user to select any dates and must ignore the 10 days back condition...so im not sure how to trigger that functionality...here is my datetimepicker control code below...

    <div class="col-xs-1">
          @*<label>Date From:</label>*@
          <label class="control-label col-sm-4" for="date from">DateFrom:</label>
      </div>
      <div class="col-xs-11">
          @(Html.Kendo().DateTimePicker()
                          .Name("KDateFrom")
                          .Value((DateTime?)ViewData["datetime"])
                             .HtmlAttributes(new { style = "width:200px" })
                             .Events(e => e.Change("OnChange"))
                          )
      </div>
      
      <div class="col-xs-1">
          @*<label>Date To:</label>*@
          <label class="control-label col-sm-4" for="date to">DateTo:</label>
      </div>
       <div class="col-xs-11">
          @(Html.Kendo().DateTimePicker()
                              .Name("KDateTo")
                                .Value((DateTime?)ViewData["datetime"])
                                 .HtmlAttributes(new { style = "width:200px" })
                              .Events(e => e.Change("OnChange"))
      
     
               )
      </div>

    As you can see i have onChange event on the grid

     function OnChange(e) {

                    $('#grid').data('kendoGrid').dataSource.read();

                                
                    
                };

  5. Answer
    Slav
    Admin
    Slav avatar
    1355 posts

    Posted 20 Jun Link to this post

    Hello Marc,

    You could set the initial value of the KDateFrom DateTimePicker to the result of subtracting 10 days from the current date:
    @(Html.Kendo().DateTimePicker()
    .Name("datetimepicker")
        .Value(DateTime.Now.AddDays(-10))
        .HtmlAttributes(new { style = "width:100%;" }).Events(e => e.Change("OnChange"))
    )
    This way you can directly use the value of the DateTimePicker regardless of whether the Grid is bound to the first time or not.

    If this is not possible in your case for some reason, you can set a flag on the onDataBound event of the Grid, which is raised each time the data is read: http://demos.telerik.com/aspnet-mvc/grid/events

    Regards,
    Slav
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    38 posts
    Member since:
    Mar 2008

    Posted 08 Jul Link to this post

    Thanks Slav, its working perfectly

     

Back to Top
UI for ASP.NET MVC is VS 2017 Ready