I've been having trouble with Full Calendar. I already tried different approaches but to no avail. The json response doesn't shows up in the calendar.
View:
<div class="col-lg-12 col-md-12">
<div id="calendar">
</div>
</div>
Controller:
public function calendar(Request $request){
if($request->ajax()){
$data= Table::where('id',Auth::user()->id)
->where('DateFrom','>',$request->start)
->where('DateTo','<',$request->end)
->get();
return response()->json($data);
}
}
Route:
Route::get('/calendar', [CalendarController::class, 'calendar'])->name('calendar');
Script (mix):
$('#calendar').fullCalendar({
events: 'calendar',
eventColor: '#378006',
displayEventTime: true,
eventRender: function (event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: true,
selectHelper: true,
})
There are no errors, the data is also being fetched but the problem is the calendar can't render it. May I ask is there any problem with this? Do I need to actually create a partial view for this and then include it to another blade file?
The problem was that I was fetching a different type of date which doesn't match up with the dates from the Fullcalendar. So to show/highlight those dates I did this.
Controller:
public function calendar(Request $request){
if($request->ajax()){
$event= Table::where('id',Auth::user()->id)
->where('DateFrom','>',date('Y-m-d',$request->start)) //converts date
->where('DateTo','<',date('Y-m-d',$request->end)) //converts date
->get();
$data = [];
foreach($event as $row){
$data[] = [
'title' => $row->title,
'start' => date(DATE_ISO8601,strtotime($row->DateFrom)),
'end' => date(DATE_ISO8601,strtotime($row->DateTo))
];
}
return response()->json(collect($data));
}
return view('partials._calendar-details',compact('data'));
}
and then for my script:
$('#calendar').fullCalendar({
// events: 'calendar',
eventColor: '#378006',
displayEventTime: false,
eventSources: [
{
events: function(start, end, timezone, callback ){
$.ajax({
url: '/calendar',
type: 'GET',
data: {
// our hypothetical feed requires UNIX timestamps
start: start.unix(),
end: end.unix()
},
dataType: 'json',
success: function(res) {
var events = [];
for (var i = 0; i < res.length; i++){
console.log(res[0].title);
events.push({
title: res[0].title,
start: res[0].start,
end: res[0].end
});
}
callback(events);
},
});
},
color: 'darkblue', // an option!
textColor: 'white', // an option!
}
],
eventRender: function (event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
},
selectable: true,
selectHelper: true,
})
Related
I tried to submit dynamic data to jscript and render the data using php from api url, but how can I pass the pagination number to the datable jscript and letting php to define the pageindex dynamically?
I tried to pass the value into the function, it will totally reload the ajax table for me and stay back at page number 1 instead of page number 2.
the api returns:
{
"data": [...],
"pageindex": 1,
"totalrecord": 708,
"totalpage": 71
}
My Form jquery:
$('.form-filter form').on('submit', function(e) {
e.preventDefault();
const start = $('.form-filter [name=start]').val();
const end = $('.form-filter [name=end]').val();
const type = $('.form-filter [name=type]').val();
const status = $('.form-filter [name=status]').val();
if (this.checkValidity() !== false) {
action_handle('fire_search');
var datetime = timezone(start, end);
paymentTable(datetime[0], datetime[1], type, status);
}
});
The datatable jscript:
function paymentTable(from, to, type, status) {
const paymentTable = $('#table').DataTable({
ajax: {
type : "POST",
url: "/api/somethinng/history",
data: {"start": from, "end": to, "type": type, "status": status},
dataSrc: function(json) {
if(json == "no data") {
return [];
} else {
return json.data;
}
}
},
responsive: {
details: {
renderer: $.fn.dataTable.Responsive.renderer.tableAll({
tableClass: 'ui display nowrap table-sm table-bordered'
})
}
},
processing: true,
serverSide: true,
deferRender: true,
destroy: true,
order: [[0,"desc"]],
}
});
paymentTable.draw();
}
My PHP function to get the data from api:
public function api_history() {
$raw = $this->balance_model->data_source([
'type' => 1,
'status' => 1,
'fromdate' => '2020-10-01',
'todate'=> '2020-10-05',
'pageindex' => 1,
'rowperpage' => 1000
]);
if( $raw['code'] == 1 && $raw['data'] != [] ):
asort($raw['data']);
$data = [];
foreach( $raw['data'] as $ph ):
$row = [];
$row[] = $ph['date'];
$row[] = $ph['id'];
$row[] = $ph['amount'];
$data[] = $row;
endforeach;
echo json_encode([
'data' => $data
'draw' => (int)$_POST['draw'],
'recordsTotal' => $raw['totalRecord'],
'recordsFiltered' => $raw['totalRecord']
]);
else:
echo json_encode(['no data']);
endif;
}
I'm trying to display events on fullcalendar in Laravel. My code is below.
This is the controller methods:
public function index()
{
return $this->eventsToArray(EtudiantEvent::all());
}
public function eventsToArray($events){
$eventArray = [];
foreach ($events as $event) {
$data = [
"titre" => $event->title,
"Debut" => $event->start_date,
"Fin" => $event->end_date,
"textColor" =>"white"
];
array_push($eventArray, $data);
}
return response()->json($eventArray);
}
This is the script:
document.addEventListener('DOMContentLoaded', function() {
const calendarEl = document.getElementById('calendar');
const calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['dayGrid', 'interaction'],
header : {
left : 'prevYear,prev,next,nextYear today',
center : 'title',
right : 'dayGridMonth, dayGridWeek, dayGridDay'
},
navLinks : true,
editable :true,
selectable : true,
eventLimit : true,
events : '/etudiantEvent'
});
calendar.render();
});
I create an edit page to edit the data. After the user edits the form. The form should be saved. But in my case I can't save the form it's showing error.
I facing this error.
ReminderComponent.vue
<script>
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import MarkdownIt from 'markdown-it'
import ClassicEditor from '#ckeditor/ckeditor5-build-classic';
var msg_editor;
Vue.use(VueAxios, axios);
const md = new MarkdownIt({
linkify: true
})
export default {
props: ['email_creation_link', 'email_index_route', 'email_edit_route','conditions','modules','mailtemplates'],
components: {
},
data() {
return {
template:
{
subject: '',
message: '' ,
days: '',
condition_id: 1,
},
options:[
{
display:'Client Name',
actual:'Client name'
},
{
display:'Joined Date',
actual:'Joined date'
},
{
display:'Module Name',
actual:'Module name'
},
{
display:'Last Seen',
actual:'Last seen'
},
],
showName: false,
}
},
mounted(){
var self = this;
ClassicEditor
.create(document.querySelector( "#msg"),
{
})
.then(editor => {
msg_editor = editor;
editor.model.document.on( 'change:data', () => {
self.template.message = msg_editor.getData();
});
})
.catch(error => {
console.error(error);
})
if (this.mailtemplates) {
this.template=this.mailtemplates;
}
},
methods: {
//Drag items
dragstart: function(item, e){
this.draggingItem = item;
e.dataTransfer.setData('text/plain', item.actual);
},
dragend: function(item,e) {
e.target.style.opacity = 1;
},
dragenter: function(item, e) {
this.draggingItem = item;
},
//content
replaceVariables(input)
{
let updated = input
return updated
},
//hidecontent
showHide: function(e)
{
console.log("Show "+e.target.value+ " fields")
this.showName = e.target.value !== ''
},
fetch()
{
//request data
axios.get(this.email_index_route,this.template)
.then((res) => {
this.template = res.data.template;
})
**axios.get(this.email_edit_route,this.mailtemplates)
.then((res) => {
this.mailtemplates = res.data.template;
})**
},
save()
{
//save data to db
axios.post(this.email_index_route, this.template)
.then((res) => {
alert('Mail sent successfull!')
})
**axios.post(this.email_edit_route, this.mailtemplates)
.then((res) => {
alert('Mail sent successfull!')
})**
},
addToMail: function(type, text)
{
if (type == 'message') {
this.template.message += text;
msg_editor.setData(this.template.message);
}
},
//user name replace
replaceVariables() {
return this.replaceVariables(this.options || '')
},
}
}
</script>
I think this area causing problem but i can't find the solution.
axios.get(this.email_edit_route,this.mailtemplates)
.then((res) => {
this.mailtemplates = res.data.template;
})
axios.post(this.email_edit_route, this.mailtemplates)
.then((res) => {
alert('Mail sent successfull!')
})
route file
Route::get('api/email/create', ['as' => 'email.create', 'uses' => 'Havence\AutoMailController#create']);
Route::get('automail/mail', 'Havence\AutoMailController#mail');
Route::get('automail/index',['as'=>'email.index','uses' => 'Havence\AutoMailController#index']);
Route::post('automail/edit/{id}',['as'=>'email.edit','uses' => 'Havence\AutoMailController#edit']);
Route::get('automail/delete',['as'=>'email.delete','uses' => 'Havence\AutoMailController#destroy']);
I kept searching for this but couldn't find an answer that will make this clear.
Thanks!
As per your error and your route file you are using POST method on your edit page but your edit method accepts only GET method that is why you are getting this error.
I'm getting this error
I have question regarding series name, How can i set static series name to the element based on the categories in the HighChart.
The expected output will be like this:
As of now I have result on my web app.
Is it possible to change that Series1,Series2,Series3 based on what I want to put on the Series name?
I have here my codes:
categories = [],
series = [];
$.getJSON('ajax/ams_sla_report_chart.php', function(data,name){
data.forEach(function(arr) {
arr.forEach(function(el, i) {
if (i === 0) {
categories.push(el);
} else if (series[i - 1]) {
series[i - 1].data.push(el);
} else {
series.push({
name:['MR','MR_HIT','MR_HIT_PERCENTAGE'],
data: [el]
});
}
});
});
var chart = new Highcharts.Chart({
chart: {
renderTo: 'containers',
type: 'column',
inverted: false
},
legend: {
layout: 'horizontal',
align: 'right',
verticalAlign: 'middle'
},
xAxis: {
categories: categories
},
title: {
text: 'Priority Based on SLA'
},
series:series
});
function showValues() {
$('#alpha-value').html(chart.options.chart.options3d.alpha);
$('#beta-value').html(chart.options.chart.options3d.beta);
$('#depth-value').html(chart.options.chart.options3d.depth);
}
// Activate the sliders
$('#sliders_eng input').on('input change', function () {
chart.options.chart.options3d[this.id] = parseFloat(this.value);
showValues();
chart.redraw(false);
});
showValues();
});
You need to define the series names array outside of the loop and use only one name in the loop:
var seriesNames = ['MR', 'MR_HIT', 'MR_HIT_PERCENTAGE'],
...
data.forEach(function(arr) {
arr.forEach(function(el, i) {
if (i === 0) {
categories.push(el);
} else if (series[i - 1]) {
series[i - 1].data.push(el)
} else {
series.push({
name: seriesNames[i - 1],
data: [el]
});
}
});
});
Live demo: http://jsfiddle.net/BlackLabel/ewauprqh/
I had a jqGrid and I had put a datepicker on the search column. When I click the datepicker, it come out and allow me to choose any date I want. However, after date selection it wont help me to filter my result. But if I type the same date on the column jqGrid will do the filtering for me.
Here is my code.
{name:columnArr4[3], index:columnArr4[3], width:106, sortable: true, fixed:true, resizable:false, // expiry date
formatter: function (cellvalue, options, rowObject)
{
celVal = '-';
if (cellvalue && cellvalue.replace(/\s/g, '').length>0){
celVal = cellvalue;
}
return celVal;
},
search:true, stype:'text', searchoptions: { dataInit: function(el) {
$(el).datepicker({
dateFormat: 'yy-mm-dd'
});
}
}
},
dataInit: function (elem) {
$(elem).datepicker({
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function() {
if (this.id.substr(0, 3) === "gs_") {
// in case of searching toolbar
setTimeout(function(){
myGrid[0].triggerToolbar();
}, 50);
} else {
// refresh the filter in case of
// searching dialog
$(this).trigger('change');
}
}
});
}