jQWidgets Forums
jQuery UI Widgets › Forums › Scheduler › addAppointment not setting the Id
Tagged: javascript scheduler, jquery scheduler, scheduler
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 8 years, 9 months ago.
-
Author
-
Hi, i’m biding the scheduler with my back-end(using json and ajax).
i’m using the addAppointment to do this, every think is ok but id is a random number not the id in the json.my code:
var source = { dataType: "array", dataFields: [{ name: 'id', type: 'string' }, { name: 'agenda_group_id', type: 'string' }, { name: 'title', type: 'string' }, { name: 'description', type: 'string' }, { name: 'professional_id', type: 'string' }, { name: 'animal_owner_id', type: 'string' }, { name: 'phone_number', type: 'string' }, { name: 'phone_type', type: 'string' }, { name: 'start', type: 'string' }, { name: 'end', type: 'string' }, { name: 'animal_id', type: 'string' }, { name: 'status', type: 'string' }, { name: 'recurrency', type: 'string' }], localData:appointments }; var adapter = new $.jqx.dataAdapter(source); /*****INICIALIZA AGENDA NO ID SCHEDULER NA DATA 1/9/2016(mudar para data atual do cliente) *****/ $("#scheduler").jqxScheduler({ date: new $.jqx.date('todayDate'), editDialog: false, width: 1351, height: 905, source: adapter, showLegend: false, ready: function() { console.log($("#scheduler").jqxScheduler('getAppointments')); $.getJSON('list_appointments',{date_begin:(new Date()).toISOString().substring(0, 8)+"01",date_end:new Date().toISOString().substring(0, 8)+"31"}, function(data) { appointments = data; setAppointments(appointments); }); console.log($("#scheduler").jqxScheduler('getAppointments')); }, resources: { colorScheme: "scheme05", dataField: "calendar", culture: 'pt-BR', source: new $.jqx.dataAdapter(source) }, appointmentDataFields: { from: "start", to: "end", id: "id", description: "description", subject: "title", resourceId: "professional", recurrencePattern: "recurrency", status: "status", }, view: 'monthView', views: [{ type: 'dayView', text: "Dia" }, { type: 'weekView', text: "Semana" }, { type: 'monthView', text: "Mês" }] });
my JS function to Add Appointments:
function setAppointments(data) { for (var i = 0; i <= data.length-1; i++) { console.log(data[i].id); $("#scheduler").jqxScheduler('addAppointment', data[i]); } }
JSON example:
[{"phone_type":"","status":"2","professional_id":105,"animal_id":"9773","title":"Banho","animal_owner_id":"","end":"2016-03-10 16:30:00","agenda_group_id":1,"start":"2016-03-10 16:00:00","phone_number":"","description":"","id":"198"},{"phone_type":"","status":"1","professional_id":105,"animal_id":"9773","title":"Consulta Quinzenal","animal_owner_id":"","end":"2016-03-01 17:30:00","agenda_group_id":1,"start":"2016-03-01 17:00:00","phone_number":"","description":"","id":"199"},{"phone_type":"","status":"1","professional_id":105,"animal_id":"4491","title":"mensal dia 15","animal_owner_id":"","end":"2016-03-15 16:30:00","agenda_group_id":1,"start":"2016-03-15 16:00:00","phone_number":"","description":"","id":"203"}]
Hi augustoMoreira,
Your binding should be through the dataAdapter. What you did is incorrect, because your dataAdapter has no value here. It should communicate with your server. addAppointment is for adding new dynamic appointments only. And as these appointments are dynamic, the id is dynamically generated by the Scheduler.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.