|
<ejs-datepicker id="startDate" placeholder="Choose a Start Date"></ejs-datepicker>
<ejs-datepicker id="endDate" placeholder="Choose a End Date"></ejs-datepicker>
<ejs-button id="btn" content="Click" isPrimary="true"></ejs-button>
<script type="text/javascript">
document.getElementById("btn").addEventListener('click', function () {
var schObj = document.querySelector(".e-schedule").ej2_instances[0];
schObj.eventSettings.query = new ej.data.Query().addParams("CustomStart", document.querySelector('#startDate').ej2_instances[0].value).addParams("CustomEnd", document.querySelector('#endDate').ej2_instances[0].value);
})
</script> |
|
[HttpPost]
public List<ScheduleEvent> LoadData([FromBody]Params param)
{
DateTime start = (param.CustomStart != new DateTime ()) ? param.CustomStart: param.StartDate;
DateTime end = (param.CustomEnd != new DateTime()) ? param.CustomEnd : param.EndDate;
return _context.ScheduleEvents.Where(app => (app.StartTime >= start && app.StartTime <= end) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList(); // Here filtering the events based on the start and end date value.
}
public class Params{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime CustomStart { get; set; }
public DateTime CustomEnd { get; set; }
} |
Hello again.
I am trying to send the dates according to your orientations in the OnActionComplete event of the Scheduler.
I can't get them to arrive in date format, the same way they arrive in the LoadData method.
I have tried to convert without success.
function onActionComplete(args) {
if (args.requestType === "viewNavigate" || args.requestType === 'dateNavigate') {
var scheduleObj = document.getElementById('scheduleAgenda').ej2_instances[0];
var selDate = scheduleObj.selectedDate;
var currentViewDates = scheduleObj.getCurrentViewDates()
var startDate = currentViewDates[0];
var endDate = currentViewDates[currentViewDates.length - 1];
console.log("onActionComplete: " + startDate);
console.log("onActionComplete: " + endDate);
console.log(Date.parse(selDate));
$.post("/Agenda/ChangeDateRange",
{
selDate: scheduleObj.selectedDate,
fechas: scheduleObj.getCurrentViewDates()
}
);
}
}
In controller obtain the dates in string format (not datetime..)
private static ParamsRangoFechas prf = new ParamsRangoFechas();
public class ParamsRangoFechas
{
public string selDate { get; set; }
//public DateTime selDate { get; set; }
public List fechas { get; set; }
}
[HttpPost]
public void ChangeDateRange(ParamsRangoFechas p)
{
prf.selDate = p.selDate;
prf.fechas = p.fechas;
}
Suggest some way to convert it?
Thanks again...
|
[HttpPost]
public List<ScheduleEvent> LoadData([FromBody]Params param)
{
//DateTime start = (param.CustomStart != new DateTime ()) ? param.CustomStart: param.StartDate;
//DateTime end = (param.CustomEnd != new DateTime()) ? param.CustomEnd : param.EndDate;
DateTime start = param.StartDate;
DateTime end = param.EndDate;
return _context.ScheduleEvents.Where(app => (app.StartTime >= start && app.StartTime <= end) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList(); // Here filtering the events based on the start and end date value.
}
public class Params
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
//public DateTime CustomStart { get; set; }
//public DateTime CustomEnd { get; set; }
} |