POPULATING DATA FROM DATABASE IN DHTMLX SCHEDULER

Hello ,

I am exploring the DHTMLX scheduler according to the requirements in our current Project.
According to the Requirement ,we want to fetch some data from database and want to display as a column against each row in day, week and month view.
Is it possible in DTMLX?

Also we want to create events by clicking on a cell and edit also on clicking on particular event . We want to display custom html/jsp page on clicking of event ,
so while open it should fetch some data from database and after saving it should save in database and display back in calender. Is it possible?

We are developing the code in java, jsp, javascript hibernate and struts .Database we are using MSSQL.

Please provide some sample code for above requirements if possible.

Hello,
According to the Requirement ,we want to fetch some data from database and want to display as a column against each row in day, week and month view.
Is it possible in DTMLX?

Do you have any sketch or mockup of how it should look like? Do you mean you want to load your data as sections of the timeline view? docs.dhtmlx.com/scheduler/timeline_view.html
If so, rows can be loaded either with data or via manual ajax request

Currently we don’t have a ready docs on loading sections of timeline/units views from the backend, but it should be really simple:

  1. When you initialize timeline, instead of sections array you use scheduler.serverList with some arbitrary collection name as an argument docs.dhtmlx.com/scheduler/api__s … rlist.html

scheduler.createTimelineView({ .... y_unit: scheduler.serverList("sections"), ... });
2) when you form scheduler data response on the backend, you use following format:
JS:

scheduler.load(dataurl, "json"); dataurl response:{ "data":[ {"id":"1","start_date":"2015-03-02 00:00:00","end_date":"2015-03-04 00:00:00","text":"dblclick me!","type":"1"}, {"id":"2","start_date":"2015-03-09 00:00:00","end_date":"2015-03-11 00:00:00","text":"and me!","type":"2"}, {"id":"3","start_date":"2015-03-16 00:00:00","end_date":"2015-03-18 00:00:00","text":"and me too!","type":"3"}, {"id":"4","start_date":"2015-03-02 08:00:00","end_date":"2015-03-02 14:10:00","text":"Type 2 event","type":"2"} ], "collections": { "sections":[ {"value":"1","label":"Simple"}, {"value":"2","label":"Complex"}, {"value":"3","label":"Unknown"} ] } }

where “data” array contains calendar events, and “collections” hash contains collections that can be referenced via scheduler.serverList method.

Alternatively, in order to load rows via ajax you’ll need scheduler.serverList/scheduler.updateCollection methods, please check this snippet
docs.dhtmlx.com/scheduler/snippet/32535c78
And related docs
docs.dhtmlx.com/scheduler/api__s … rlist.html
docs.dhtmlx.com/scheduler/api__s … ction.html

As for creating/editing events, if you want to use separate pages actions, you can capture onEmptyClick/onClick events
docs.dhtmlx.com/scheduler/api__s … event.html
docs.dhtmlx.com/scheduler/api__s … event.html

Here is a small demo:
docs.dhtmlx.com/scheduler/snippet/f67e9737

Hello Allaksandr,

Thanks for your updates. I was trying to upload data from database and display into the timeline view but I was not able to display.

When I changed the view to month ,data was coming what is the problem in timeline view.

Given below is my jsp page.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<%-- <script type="text/javascript" charset="utf-8" src='<s:url value="./js/dhtmlxscheduler.js"/>'></script> --%>
<script type="text/javascript" charset="utf-8" src="./codebase/dhtmlxscheduler.js"></script>
<link rel="stylesheet" href="./codebase/dhtmlxscheduler.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="./codebase/ext/dhtmlxscheduler_limit.js" type="text/javascript" charset="utf-8"></script>
<%-- <script src="./codebase/ext/dhtmlxscheduler_dhx_terrace.js" type="text/javascript" charset="utf-8"></script> --%>
<script src="./codebase/ext/dhtmlxscheduler_minical.js" type="text/javascript" charset="utf-8"></script>
<script src="./codebase/ext/dhtmlxscheduler_timeline.js" type="text/javascript" charset="utf-8"></script>
<style media="screen">
	html, body{
		margin:0px;
		padding:0px;
		height:100%;
		overflow:hidden;
	}

	.dhx_cal_event {
		z-index: 1;
		cursor: pointer;
	}
	.highlighted_timespan {
		
		opacity:0.5;
		filter:alpha(opacity=50);
		cursor: pointer;
		z-index: 0;
	}
</style>
<script charset="utf-8">
function init() {
	
	scheduler.config.xml_date="%Y-%m-%d %H:%i";
 	 var sections=[
        {key:1, label:"Open shift"},
		{key:2, label:"James Smith"},
		{key:3, label:"John Williams"},
		{key:4, label:"David Miller"},

	];  


	
	scheduler.createTimelineView({
		name:	"timeline",
		x_unit:	"minute",
		x_date:	"%H:%i",
		x_step:	30,
		x_size: 12,
		x_start: 16,
		x_length:	48,
		y_unit:	sections,
		y_property:	"section_id",
		render:"bar"
	});


	scheduler.init("scheduler_here",new Date(2014,5,30),"timeline");
	

    scheduler.load("myconnector.do?uid="+scheduler.uid());
	

}

</script>
</head>
<body onload="init();">

<div id="scheduler_here" class="dhx_cal_container" style="width:100%; height:100%;">
	<div class="dhx_cal_navline">
		<div class="dhx_cal_prev_button">&nbsp;</div>
		<div class="dhx_cal_next_button">&nbsp;</div>
		<div class="dhx_cal_today_button"></div>
		<div class="dhx_cal_date"></div>
		<!-- <div  name="day_tab"  onclick="tempday();" style="right:204px;"></div>
		<div class="" name="week_tab" onclick="tempWeek();"style="right:140px;"></div>
		<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div> -->
		<div class="dhx_cal_tab" name="timeline_tab" "style="right:76px;"></div>
		
	</div>
	<div class="dhx_cal_header">
	</div>
	<div class="dhx_cal_data">
	</div>
</div>

</body>
</html>


Given below my connector code.

[code]
package com;
import java.sql.Connection;
import java.sql.DriverManager;

import com.dhtmlx.connector.ConnectorServlet;
import com.dhtmlx.connector.DBType;
import com.dhtmlx.connector.SchedulerConnector;

public class Myconnector extends ConnectorServlet{

@Override
protected void configure() {
	  //obtain DB connection
	try {
	Connection conn=null;
    
      Class.forName ("org.postgresql.Driver").newInstance ();
      conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/sampleDb","postgres","postgre@123");
   

    //Initialize connector
    SchedulerConnector c = new SchedulerConnector(conn, DBType.PostgreSQL);
       // c.servlet(req, res);
    //configure used table and fields
    c.render_table("events", "event_id", "start_date,end_date,details");
	
}
 catch (Throwable e) {
    e.printStackTrace();
}

}

}[/code]

Below output I am getting from the connector.

<?xml version='1.0' encoding='utf-8' ?><data><event id='2' ><start_date><![CDATA[2014-06-30 09:00:00]]></start_date><end_date><![CDATA[2014-06-30 12:00:00]]></end_date><text><![CDATA[french open coutrtier paris france new]]></text></event> </data>.

please suggest what I am lacking ?

The issue has been resolved by myself, actually the mandatory section_id for timeline view was not coming through database. :laughing:

Hello Allaksandr,

For populating the section information from database , not clear from the point you mention above .

What is the point you mention given below
point2: when you form scheduler data response on the backend, you use following format:
scheduler.load(dataurl, “json”);

1.what is the parameter dataurl you mentioned here? currently i am using scheduler.load(“myconnector.do”) in my client jsp . Which is the path of my connector servlet to databse.

2.If I use this what are necessary changes i have to do at my server side connector servlet(code i mentioned in above queries).

  1. How the response will come including the data and collections having the sections also in response? Do I need to change my database column also?

  2. Requesting you to please respond with code snippet having looking into my jsp and connector servlet shared in above queries?

  3. Also I want to check if we are using stored procedure which will return multiple resultset how can we use in my connector servlet?please give some code snippet also?

Hello.

dataurl is server side url which outputs data to client side.
To send options to client side you could use OptionsConnector.
For example, something like following:

		Connection conn= ( new DataBaseConnection()).getConnection();

		JSONOptionsConnector list = new JSONOptionsConnector(conn);
		list.render_table("types","typeid","typeid(value),name(label)");

		JSONSchedulerConnector scheduler = new JSONSchedulerConnector(conn);
		scheduler.set_options("type", list);
		scheduler.render_table("tevents","event_id","start_date,end_date,event_name,type");

To run stored procedure you could try to use render_complex_sql.
For example, something like following:

		Connection conn= ( new DataBaseConnection()).getConnection();
		SchedulerConnector c = new SchedulerConnector(conn);
		c.render_complex_sql("CALL EVENTS;", "event_id", "start_date,end_date,event_name,details");