Populating a select from database in DHX Scheduler


Firstly, I’d like to say thank you for a great calendar/scheduler.

I’ve got the scheduler loading and saving events from mySql database. I’d like to populate a select in the lightbox with some names from my db. This is my client code:

function init() {
			scheduler.config.xml_date="%Y-%m-%d %H:%i";
			scheduler.config.first_hour = 8;
			scheduler.config.last_hour = 20;
			scheduler.config.details_on_create = true;
			scheduler.config.details_on_dblclick = true;
			scheduler.config.prevent_cache = true;

			scheduler.locale.labels.section_coach = "Coach:";
			scheduler.locale.labels.section_student = "Student:";	

			var sections = [
				{key:'coach1', label:'Coach 1'},
				{key:'coach2', label:'Coach 2'}

			var students = [
				{key:'student1', label:'Student 1'},
				{key:'student2', label:'Student 2'}
			scheduler.config.lightbox.sections = [
				{ name:"description", height:130, map_to:"text", type:"textarea" , focus:true },
				{ name:"student", height:72, type:"select", options:students, map_to:"student", filtering: true },
				{ name:"coach", height:43, type:"select", options:sections, map_to:"coach", filtering: true },
				{ name:"time", height:72, type:"time", map_to:"auto" }

			scheduler.templates.event_class=function(start, end, event){
                if(event.coach) // if event has subject property then special class should be assigned
                    return "event_"+event.coach;

                return ""; // default return



			var dp = new dataProcessor("data/connector.php");

			var calendar = scheduler.renderCalendar({
					scheduler.setCurrentView(date, scheduler._mode);
			scheduler.setCurrentView(scheduler._date, scheduler._mode);

This is my connector:

$conn = new SchedulerConnector($res);

I’m not great at javascript - can someone please tell me how to get my students options from the database instead of an array?

I’d like the first name and last name concatenated together in my select.

I really appreciate the help.


Is anyone able to help with this?

Can someone please help. I’m not sure whether to add the code from the examples to my existing connector.php (which is where my data is coming from) or whether to create a new one. I’ve looked through samples and the client code seems fairly easy but the instructions aren’t clear for the sever-side. I just need to populate a select in the lightbox in the scheduler with some names from a different table in my database. The events are being saved into a bookings table, but I need the names of the students to come from a students table.

check ‘connector_options’ example from php connectors package:

Options can be loaded with the rest of data, and attached to the client with with ‘serverList’ api,
client:... scheduler.config.lightbox.sections = [ {name:"description", height:200, map_to:"text", type:"textarea" , focus:true}, {name:"type", height:21, map_to:"type", type:"select", options:scheduler.serverList("type")},//<--here it is {name:"time", height:72, type:"time", map_to:"auto"} ];server:[code] …

$list = new OptionsConnector($res);

$scheduler = new schedulerConnector($res);

//add options to the primary connector
$scheduler->set_options("type", $list);


Thanks for your reply.

It’s this line I dont get:


Say I have a table called ‘clients’ and I want to take the firstName from each of the rows and use that as the ‘type’ to list in the dropdown. How do I get it fom the database using your example?

It’s the typeid(value) and and name(value) that’s throwing me. Is this code added to my existing connector? DO I need to use the options_connector.php aswell as the scheduler connector?

I appreciate your patience.


I’ve used the below code and it’s listing null as each of the select options:


$list = new OptionsConnector($res);

$conn = new SchedulerConnector($res);

$conn->set_options("student", $list);

I get the below in the log so it seems to be connecting ok.

Log started, 23/02/2013 04:49:51

SELECT booking_id,start_date,end_date,text,coach,student FROM bookings

SELECT clientId,firstName,lastName FROM clients

Done in 0.019742965698242s

It also seems to be getting the correct number of items from the database (7 in total) but each option is coming out as null.

How can i get it to output values rather than null?

Surely there’s someone here who can assist?






And it will show something more meaningfull
As you need to show both fields as text, you may need to use more complex command, like

$list->render_sql("SELECT clientId, clientId as value, CONCAT (firstName, " ", lastName) as label FROM clients", "clientId", "value, label");