StartDate and EndDate parameter values

Hello,

how can I pass StartDate and EndDate value without adding or substracting GMT time? I am in time zone with GMT+3 so when I am requesting to WebAPI the component subtracts 3 hours from time:

Normal time for StartDate without GMT subtraction should be 2019-07-10T00:00:00.000Z

If there are no property for that - maybe I can add it with some additional property?

Now I am trying to do it in actionBegin event but I should get current dates with setTimeout because I found dates only in schedule activeview property and for that reason my parameters are added too late (so I need to set again dataSource manually so there are additional not necessary request to WebAPI).

I am doing it like this:
     @ViewChild('mySchedule') Schedule: Schedule;
     public eventSettings: EventSettingsModel;
     
     public onActionBegin(args) {
setTimeout(() => {
let format = this.listHelper.getDateTimeFormatByLocale(this.locale, 'datetime');
format = format.substring(0, 10).toUpperCase() + format.slice(10);

const startDateCurrentEvent = this.eventSettings.query['params'].indexOf(this.eventSettings.query['params'].find(i => i.key === 'StartDateCurrent'));
if (startDateCurrentEvent != -1)
this.eventSettings.query.params.splice(startDateCurrentEvent, 1);
const endDateCurrentEvent = this.eventSettings.query['params'].indexOf(this.eventSettings.query['params'].find(i => i.key === 'EndDateCurrent'));
if (endDateCurrentEvent != -1)
this.eventSettings.query.params.splice(endDateCurrentEvent, 1);

this.eventSettings.query['params'].push(<any>{
key: 'StartDateCurrent',
value: (this.Schedule.activeView == undefined)
? moment(moment(), format).hours(0).minutes(0).seconds(0).milliseconds(0).format('YYYY-MM-DD[T]HH:mm:ss.SSS[Z]')
: moment(this.Schedule.activeView.renderDates[0], format).milliseconds(0).format('YYYY-MM-DD[T]HH:mm:ss.SSS[Z]')
});
this.eventSettings.query['params'].push(<any>{
key: 'EndDateCurrent',
value: (this.Schedule.activeView == undefined)
? moment(moment(), format).add(1, 'days').hours(0).minutes(0).seconds(0).milliseconds(0).format('YYYY-MM-DD[T]HH:mm:ss.SSS[Z]')
: moment(this.Schedule.activeView.renderDates[this.Schedule.activeView.renderDates.length - 1], format).add(1, 'days').milliseconds(0).format('YYYY-MM-DD[T]HH:mm:ss.SSS[Z]')
});

this.setDataSource();
// this.eventSettings.dataSource = this.GPHttpContextService.getDataManager(this.Settings.Url);
});

}




1 Reply

KK Karthigeyan Krishnamurthi Syncfusion Team July 10, 2019 11:48 AM UTC

Dear Customer, 
 
Syncfusion greetings. 
 
By default, Scheduler will send the data in 0 UTC to server which is the cause. Custom adaptor can be used to achieve your requirement like below. 
 
class CustomAdaptor extends UrlAdaptor { 
  public beforeSend(args: DataManager, xhr: XMLHttpRequest) { 
    console.log(xhr); 
    xhr.withCredentials = true; 
    super.beforeSend(args, xhr); 
  } 
  processQuery(dm, query, hierarchyFilters): Object { 
    let req = {}; 
    let r = { 
      sorted: [], 
      grouped: [], 
      filters: [], 
      searches: [], 
      aggregates: [] 
    }; 
    let filterQueryLists = function (queries, singles) { 
      let filtered = queries.filter(function (q) { 
        return singles.indexOf(q.fn) !== -1; 
      }), res = {}; 
      for (let i = 0; i < filtered.length; i++) { 
        if (!res[filtered[i].fn]) 
          res[filtered[i].fn] = filtered[i].e; 
      } 
      return res; 
    }; 
    let callAdaptorFunc = function (obj, fnName, param, param1) { 
      if (obj[fnName]) { 
        let res = obj[fnName](param, param1); 
        if (!isNull(res)) param = res; 
      } 
      return param; 
    }; 
    let getValue = function (value, inst) { 
      if (typeof value === "function") 
        return value.call(inst || {}); 
      return value; 
    }; 
    let isNull = function (val) { 
      return val === undefined || val === null; 
    }; 
    let singles = filterQueryLists(query.queries, ["onSelect", "onPage", "onSkip", "onTake", "onRange"]); 
    let op = this.options; 
    req[op.from] = query._fromTable; 
    if (op.expand) req[op.expand] = query._expands; 
    req[op.select] = singles["onSelect"] ? callAdaptorFunc(this, "onSelect", getValue(singles["onSelect"].fieldNames, query), query) : ""; 
    req[op.count] = query._requiresCount ? callAdaptorFunc(this, "onCount", query._requiresCount, query) : ""; 
    req[op.search] = r.searches.length ? callAdaptorFunc(this, "onSearch", r.searches, query) : ""; 
    req[op.skip] = singles["onSkip"] ? callAdaptorFunc(this, "onSkip", getValue(singles["onSkip"].nos, query), query) : ""; 
    req[op.take] = singles["onTake"] ? callAdaptorFunc(this, "onTake", getValue(singles["onTake"].nos, query), query) : ""; 
    req[op.where] = r.filters.length || r.searches.length ? callAdaptorFunc(this, "onWhere", r.filters, query) : ""; 
    req[op.sortBy] = r.sorted.length ? callAdaptorFunc(this, "onSortBy", r.sorted, query) : ""; 
    req[op.group] = r.grouped.length ? callAdaptorFunc(this, "onGroup", r.grouped, query) : ""; 
    req[op.aggregates] = r.aggregates.length ? callAdaptorFunc(this, "onAggregates", r.aggregates, query) : ""; 
    req["param"] = []; 
 
    if (this.options.requestType === "json") { 
 
      return { 
        data: JSON.stringify(req), 
        url: 'http://localhost:54738/Home/LoadData?' + query.params[0].key + '=' + this.removeTimzeOffset(query.params[0].value) + '&' + query.params[1].key + '=' + this.removeTimzeOffset(query.params[1].value), 
        type: "POST",   
        contentType: "application/json; charset=utf-8" 
      } 
    } 
  } 
  removeTimzeOffset(value) { 
    // To add offset with StartDate and EndDate 
    let targetTime = new Date(value); 
    let tzDifference = new Date().getTimezoneOffset(); 
    return new Date(targetTime.getTime() - (tzDifference * 60 * 1000)).toISOString() 
  } 
} 
 
private dataManager: DataManager = new DataManager({ 
    url: 'http://localhost:54738/Home/LoadData', 
    crudUrl: 'http://localhost:54738/Home/UpdateData', 
    adaptor: new CustomAdaptor, 
    crossDomain: true 
  }); 
 
Regards, 
Karthi 
 


Loader.
Up arrow icon