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

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

4 Answers 134 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Marc Plaxton-Harrison
Top achievements
Rank 1
Marc Plaxton-Harrison asked on 14 Jun 2016, 12:34 PM

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

4 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 16 Jun 2016, 08:17 AM
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
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 16 Jun 2016, 07:54 PM

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

                            
                
            };

0
Accepted
Slav
Telerik team
answered on 20 Jun 2016, 10:52 AM
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
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 08 Jul 2016, 09:10 AM

Thanks Slav, its working perfectly

 

Tags
Date/Time Pickers
Asked by
Marc Plaxton-Harrison
Top achievements
Rank 1
Answers by
Slav
Telerik team
Marc Plaxton-Harrison
Top achievements
Rank 1
Share this question
or