synch server timelineLoad and timeline x-axis

Hi guys,

I am loading data to the timeline view. Basically I want to show staff on the Y-Axis that have shifts in the current timeline view. So if the time line is the next two weeks i need to show only the staff who have shifts in that period (e.g. this might only be 5 staff out of a total of 100).

on the server I find the staff in this way:

$staffQuery = “SELECT type_id as value, staff as label from v_schedule_tl WHERE start_date > ‘$_GET[from]’ AND end_date < ‘$_GET[to]’”;
$staffList = new OptionsConnector($connection);
$staffList->render_sql($staffQuery,“type_id”,“type_id(value),name(label)”);
$scheduler->set_options(“sections”, $staffList);

Which effectively selects the staff which work in the time period sent up in the server request (i have set scheduler.setLoadMode(“week”):wink:

then i find the shifts they have worked using

$shiftQuery = “SELECT id, type_id,text, start_date, end_date FROM v_schedule_tl”;
$scheduler->render_sql($shiftQuery,“id”,“start_date,end_date,text,type_id”);

So this is all ok. But when I click on the left/right arrows on the timeline on scheduler it gets all out of synch, i.e. the from and to date shown on the timeline aren’t consistent with what the DHTMLX library sends up as the from/to dates in the server request. How can i configure the timeline to match the date span in the server request, particularly so that only staff who have a shift are shown in the Y-Axis.

Here is my scheduler config for info.

cheduler.locale.labels.timeline_tab =“Timeline”;

			scheduler.locale.labels.section_custom="Section";
			scheduler.config.details_on_create=true;
			scheduler.config.details_on_dblclick=true;
			scheduler.config.dblclick_create = false;
			scheduler.config.drag_move = false;
			scheduler.config.drag_resize= false;
			scheduler.config.xml_date="%Y-%m-%d %H:%i";
			scheduler.config.show_loading = true;
			scheduler.setLoadMode("week");


			scheduler.createTimelineView({
			     name:"timeline",
			     x_unit:"day",//measuring unit of the X-Axis.
			     x_date:"%D %d %M", //date format of the X-Axis
			     x_step:1,      //X-Axis step in 'x_unit's
			     x_size:21,      //X-Axis length specified as the total number of 'x_step's
			     x_start:1,     //X-Axis offset in 'x_unit's
			    // x_length:1,    //number of 'x_step's that will be scrolled at a time
			   
			     y_unit:scheduler.serverList("sections"),    
			     y_property:"type_id", //mapped data property
			     render:"bar",             //view mode
			     round_position:true,
			     section_autoheight:false,
			     dy:25,
			     second_scale:{
			        x_unit: "week", // the measuring unit of the axis (by default, 'minute')
			        x_date: "%W" //the date format of the axis ("July 01")
			    }
			});

			scheduler.init('scheduler_here', new Date(), "timeline");
			scheduler.load("ccproc/utracserver.php?server_req=timelineLoad&req_type=api", "xml");	

thanks!
Cyril

If you are using multi-day events, change your code from
WHERE start_date > ‘$_GET[from]’ AND end_date < ‘$_GET[to]’";
to
WHERE start_date < ‘$_GET[to]’ AND end_date > ‘$_GET[from]’";

In common case you can’t be sure that server parameters match the client side view.
Client side stores already loaded data in cache, so it will not reload it from server side when the same data range shown second time, or may reload only part of data ( request will have different from and to values )

If you have active support subscription - please open a ticket in the support system. I think it will be pretty easy to add an extension which will hide empty sections on client side.

Yeah I think we will need to have a way of hiding empty sections, is it not possible to know which are the currently shown start and end dates on the client side using an event when the prev/next buttons are pressed? Then we could send these dates to the server to do the first query to find only sections which are active in those dates…

We don’t currently have a support subscription :frowning:

Hi,

you can attach “onViewChange” event to know which are the currently shown start and end dates:

scheduler.attachEvent("onViewChange", function (new_mode , new_date){ var view_start = new_date; // or scheduler._min_date; var view_end = scheduler._max_date; });
docs.dhtmlx.com/scheduler/api__s … event.html

yep, onViewChange will work, but instead of private propertis it will be better to use the getState API

var start = scheduler.getState().min_date; var end = scheduler.getState().max_date;

Thanks for this… but how can I pass those values to the server in the load request? right now I am using the from and to, can I also send the min_date / max_date ?

  • do not use setLoadMode
  • from onViewChange call something like next

    scheduler.load(“my.php?from=”+from+"&to="+to)

where from and to can be obtained with above code.

hi Stanislav,

when I do this I seem to get stuck in a loop on the onViewChange function, I can see the requests to the server firing constantly - please see my code below…

function initGantt() {
scheduler.locale.labels.timeline_tab =“Timeline”;

			scheduler.locale.labels.section_custom="Section";
			scheduler.config.details_on_create=true;
			scheduler.config.details_on_dblclick=true;
			scheduler.config.dblclick_create = false;
			scheduler.config.drag_move = false;
			scheduler.config.drag_resize= false;
			scheduler.config.xml_date="%Y-%m-%d %H:%i";
			scheduler.config.show_loading = true;
			//scheduler.setLoadMode("week");

		scheduler.createTimelineView({
			     name:"timeline",
			     x_unit:"day",//measuring unit of the X-Axis.
			     x_date:"%D %d %M", //date format of the X-Axis
			     x_step:1,      //X-Axis step in 'x_unit's
			     x_size:21,      //X-Axis length specified as the total number of 'x_step's
			     x_start:1,     //X-Axis offset in 'x_unit's
			    // x_length:1,    //number of 'x_step's that will be scrolled at a time
			   
			     y_unit:scheduler.serverList("sections"),    
			     y_property:"type_id", //mapped data property
			     render:"bar",             //view mode
			     round_position:true,
			     section_autoheight:false,
			     dy:25,
			     second_scale:{
			        x_unit: "week", // the measuring unit of the axis (by default, 'minute')
			        x_date: "%W" //the date format of the axis ("July 01")
			    }
			});


			scheduler.attachEvent("onViewChange", function (new_mode , new_date){

			  	var start = formatDate(scheduler.getState().min_date, 'y-MM-dd');
				var end = formatDate(scheduler.getState().max_date, 'y-MM-dd');
				scheduler.load("ccproc/utracserver.php?server_req=timelineLoad&req_type=api&start="+start+"&end="+end, "xml");

			});

			scheduler.init('scheduler_here', new Date(), "timeline");
			  	var start = formatDate(scheduler.getState().min_date, 'y-MM-dd');
				var end = formatDate(scheduler.getState().max_date, 'y-MM-dd');
			scheduler.load("ccproc/utracserver.php?server_req=timelineLoad&req_type=api&start="+start+"&end="+end, "xml");
		}

Hi guys,

any update on this?

thanks
Cyril.