I'm trying to show events from the database on to the calendar but I'm getting the
alert('failed') call every time.
Please, anyone, help me solve this issue. I'm stuck here.
here is my script code:
$.ajax({
url:'events',
type: "GET",
cache: false,
datatype: 'json',
success: function(data){
alert('Hello');
$.each(data, function(index, val){
events.push({
title: val.name,
start_date: val.start_date,
end_date: val.end_date,
start_time: val.start_time,
end_time: val.end_time,
location:val.location,
description: val.description,
timezone:val.timezone,
alldDay: val.isFullDay
});
})
GenerateCalendar(events);
},
error : function(error){
alert('Failed');
}
});
function GenerateCalendar(events){
$('#calendar').fullCalendar('destroy');
$('#calendar').fullCalendar({
contentHeight: 400,
defaultDate: new Date(),
timeFormat:'h(:mm)a',
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventLimit: true,
eventColor: '#378006',
events: events
});
}
Controller Function:
public function getEvents()
{
$events = Event::all();
return response()->json(['data'=> $events])->getData();
}
Thanks in advance.
I see your event has the attributes
start_date, end_date, start_time, end_time
i have not seen anything about it in the fullcalendar documentation.
as far as i know, fullcalendar expects the events to have an attribute called start which is required and an optional called end
From the fullCalendar documentation:
start - The date/time an event begins. Required. A Moment-ish input, like an ISO8601 string. Throughout the API this will become a real Moment object.
If you want to use a JSON feed to get the events there is no need to make your own ajax call. you can use the eventSource property and fullCalendar will handle the fetching for you
Related
I'm trying to change the minTime in fullcalendar according to the database schedule through an ajax request on the viewRender, but it goes into a loop.
Part of my calendarOptions:
var calendarOptions = {
header: {
left: ' today',
center: 'prev,title,next',
right: 'agendaWeek,resourceDay'
},
defaultView: 'resourceDay',
The viewRender:
viewRender: function(view, element){
var curDate = ($('#calendar').fullCalendar('getDate')).format('d-DD-MM').split('-');
var curWeekDay = curDate[0];
var curMonthDay = curDate[1];
var curMonth = curDate[2];
$.ajax({
url: 'calendar/getBusinessHours',
type: 'GET',
data: {
'day': curWeekDay,
"_token": $('body').find( 'input[name=_token]' ).val()
},
success: function (response) {
$('#calendar').fullCalendar("destroy");
$("#calendar").fullCalendar(
$.extend(calendarOptions, {
defaultDate: currentDate,
minTime: response[0].open_time+':00',
maxTime: response[0].close_time+':00'
})
);
}
});
},
The ajax response is '08:00:00' so there is no problem there;
I have not tested this but I believe your problem comes from destroying fullCalendar and setting it up again. Essentially, what happens is that your calendar loads and the view is rendered, then you make an ajax request, destroy the calendar, create a new one which triggers viewRender again and so on.
success: function (response) {
$('#calendar').fullCalendar("destroy");
$("#calendar").fullCalendar(...
You can either load the minTime and maxTime before initializing the calendar (getting the values from the database with an ajax call and initializing the calendar only when the values are retrieved from the back-end so you can pass them to the initialization as options) or change their values inside a different event (not viewRender)
What you can also do is add a variable to the equation and launch the AJAX conditionally - if the calendar is not in a process of reconstructing itself with the new minTime and maxTime.
I am trying different ways of rendering json data from mysql/php to Highcharts. So far I've been successful rendering bar charts using this approach but for some reason, I have not been able to render data in a pie chart.
One js file handles the AJAX call:
$(function () {
var select_program = program_type_php;
var select_year = '2016';
console.log ('pie_chart'+program_type_php);
$.ajax({
url: 'model/job_group_pie_chart.php',
data: {user: 2, select_program:select_program, select_year:select_year},
type: 'GET',
async: true,
dataType: "json",
success: function (year_2016) {
pie_chart_2016(year_2016);
console.log('data 2016 job groups'+year_2016);
}
});
Upon success, I call a function in another js file (in this example, 'pie_chart_2016' and pass it the data object.
Here's the other js file responsible for rendering the data into a Highchart:
function pie_chart_2016 (year_2016) {
console.log('year_2016'+year_2016);
$('#pie-chart1').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
},
showInLegend: true
},
series: year_2016
}
});
};
I have checked, and I do get valid json from my php file:
[{name:"Group1",y:829},{name:"Group2",y:9247},{name:"Group3",y:71}]
These are raw counts (829, 9247, 71) but when I was able to get a pie chart to render by inputting values manually, Highcharts calculated the percentages for me - nice!
I've also set up enough console.logs to know that my functions are being called, and that my data object is being processed.
Still, all I get is a blank panel, and 'highcharts.com' in the lower left hand corner, so the html is working too.
The approach I'm using works really well with bar charts, so I am stumped!
Thanks for any help you can provide.
Thanks to Rahul, I moved 'series:' outside of plotOptions, and added these lines. I should have caught this sooner, that pie charts needs the 'data' property while bar charts have that included in their JSON array. Appears to be working well for now. Thanks again Rahul!
series: [{
name: 'Job Group',
colorByPoint: true,
data: year_2016
}]
i hava jqxDropDownlist like this
var source = {
datatype: “json”,
datafields: [{ name: 'title'}, { name: 'id'}],
id: ‘id’,
url: “getOnvaneOrganizations”,
async: true
};
var dataAdapter = new $.jqx.dataAdapter(source);
$(“#slc_onvane_organization_sabt”).jqxDropDownList({
selectedIndex: 0,
source: dataAdapter,
displayMember: “title”,
valueMember: “id”,
theme: ‘darkblue’,
filterable:true,
width:’100%’,
rtl:true
});
$(“#slc_onvane_organization_sabt”).jqxDropDownList(‘val’,’10′);
because async is true so then $("#slc_onvane_organization_sabt").jqxDropDownList('val','10'); runs before ajax success, and not worked.
how can run $("#slc_onvane_organization_sabt").jqxDropDownList('val','10'); in ajax.success function?
please help me
jqxDataAdapter: downloadComplete(edata, textStatus, jqXHR): A callback
function which is called if the request succeeds. The function gets
passed three arguments: The data returned from the server, formatted
according to the dataType parameter; a string describing
jqxDataAdapter
and for other element like jqxdropdownlist have bindingComplete
This event is triggered when the data binding operation is completed.
Code example
Bind to the bindingComplete event by type: jqxDropDownList.
$("#jqxDropDownList").on('bindingComplete', function (event) { });
Try it: Bind to the bindingComplete event by type:jqxDropDownList
so then with this code can change value of jqxDropDownList when bindingComplete
$("#slc_onvane_organization_sabt").on('bindingComplete', function (event) {
$("#slc_onvane_organization_sabt").jqxDropDownList('val','10');
});
My general problem is that I want to have a Javascript variable which I then use with select2, to prepare the options for a select multiple. I have a fairly large array (7000 objects) and just want to store that once in a variable rather than constantly polling the server with search terms. Here is what I got.
The HTML is simply:
<input type="hidden" id="group_a" multiple="multiple" placeholder="Select at least two treatments">
Now, when I write the variable directly everything works as expected:
var treatments = [{id: 1, text: "you"}, {id: 2, text: "me"}];
$("#group_a").select2({
data: treatments,
minimumInputLength: 1,
multiple: true,
closeOnSelect: false,
width: "660px"
});
However, when I use ajax to load the array things get weird. My code to do that:
$.ajax({
url: '/funny/url',
}).done(function(data) {
treatments = data.choices;
});
I tend to get the following error unless I use the debugger to step through the code, then it works as expected. So could this somehow be a timing issue?
uncaught exception: query function not defined for Select2 group_a
My complete javascript looks like below and I've also prepared a fiddle which shows the same error.
$(document).ready(function() {
var treatments;
$.ajax({
url: '/funny/url',
}).done(function(data) {
treatments = data.choices;
});
$("#group_a").select2({
data: treatments,
minimumInputLength: 1,
multiple: true,
closeOnSelect: false,
width: "960px"
});
});
The ajax call is asynchronous, so at the time you are instrumenting the Select2 control, treatments is still undefined.
You could do the following:
$(document).ready(function() {
$.ajax({
url: '/funny/url',
}).done(function(data) {
$("#group_a").select2({
data: data.choices,
minimumInputLength: 1,
multiple: true,
closeOnSelect: false,
width: "960px"
});
});
});
jsfiddle
Better yet though, I would do the following.
Initially set treatments to an empty array, and use a function for the data option so if treatments is changed, the changes will be picked up by the Select2 control. That way, you can instrument the Select2 control right away, and then update treatments with the data returned by the ajax call. Additionally, you could initially disable the Select2 control, and then enable it when the ajax call returns.
$(document).ready(function() {
var treatments = [];
$.ajax({
url: '/funny/url',
}).done(function(data) {
treatments = data.choices;
$("#group_a").select2('enable', true);
});
$("#group_a").select2({
data: function() { return { results: treatments }; },
minimumInputLength: 1,
multiple: true,
closeOnSelect: false,
width: "960px"
}).select2('enable', false);
});
jsfiddle
The third option would be to keep your original code, but make the ajax call synchronous. I recommend not doing that though. When you make an ajax call synchronous, you lock up the entire browser.
Here is my solution. Thanks to #John S for the initial approach, but I couldn't get the select2 formatter to parse my array. Select2 box would tell me 'no results found.' I ended up running a for loop through my array and writing out the :id, :text hashes.
Starting with my json ajax call is an array of string 'terms':
// localhost:3000/search/typeahead_terms_all.json
[
"Super Term",
"cool term",
"killer term",
"awesome term",
"try term",
"param term",
"try name",
"Academic Year",
"grade average",
"Hello Term",
"Academic Calendar",
"kinda cool term",
"My Term",
]
Then the javascript:
$(document).ready(function() {
var term_names_array = [];
$.ajax({
url: '/search/typeahead_terms_all',
}).done(function(data) {
// Here I iterate through my array of strings and write out the hash select2 needs
for (index = 0; index < data.length; ++index) {
term_names_array.push({ id: index, text: data[index] });
}
$('.report_term_input').select2('enable', true);
});
$('.report_term_input').select2({
dataType: 'json',
data: term_names_array,
multiple: true,
width: "500px"
});
});
I have three parameters startdate, enddate and name which I have to send to the server to get back Json response. I am displaying the response in a GridPanel.
My Ajax Request looks like this:
FilterOperSet: function(button){
var win = button.up('window');
var form = win.down('form');
var start = form.getForm().findField('startDate').getSubmitValue();
var end = form.getForm().findField('endDate').getSubmitValue();
var act = form.getForm().findField('actor').getSubmitValue();
Ext.Ajax.request({
url: 'ListData',
params: { type: 'recordedRequest', startDate: start,
endDate: end, actor: act, start:0,limit:10 },
success: function(response) {
var json = Ext.decode(response.responseText);
var mystore = Ext.data.StoreManager.lookup('RecordedRequestStore');
mystore.loadData(json.recordedRequests);
},
scope: this});
}
I have a button, when user enters values for startdate, enddate and name and clicks on the button the above listener sends them as parameters along with start and limit for paging and response is captured and stored in gridpanel.
My issue with paging toolbar is: I could see the following as response
recordedRequests
// has some meta data here
success
true
total
1339
But my paging tool bar show only one page and at bottom says 0 of 0 and to the right nothing to display. Infact it should say 1 of 14 and should allow me to go through next pages.
2) Also when I click on refresh button it calls my store and calls server, but i want to make a ajax request with startdate, enddate and name as parameters(which would be exactly what my button above listerner does)
My Store looks like this:
autoLoad: false,
remoteFilter: true,
buffered: false,
pageSize: 10,
//leadingBufferZone: 1000,
fields:['start', 'end', 'actor','serviceOp'],
proxy: {
type: 'ajax',
url: 'ListData',
store: 'RecordedRequestStore',
startParam:'start',
limitParam:'limit',
pageParam:'page',
reader: {
type: 'json',
root: 'recordedRequests',
successProperty: 'success',
totalProperty: 'total'
},
extraParams: {
'type': 'recordedRequest',
},
//sends single sort as multi parameter
simpleSortMode: true,
// Parameter name to send filtering information in
filterParam: 'query',
// The PHP script just use query=<whatever>
encodeFilters: function(filters) {
return filters[0].value;
}
},
listeners: {
filterchange: function(store, filters, options){
console.log( filters )
},
totalcountchange: function() {
console.log('update count: ')
//this.down('#status').update({count: store.getTotalCount()});
}
}
Any sort of help will of great value for me. Thanks in Advance.
Instead of Ajax Request. I should use
store.load(params{your params})
For nextpage and previouspage I used beforeload listener for custom parameters.