Redraw Datatables after action - php

Im having problems getting my datatable to refresh. I have a button which calls an update script and a confirmation message before it does anything. This all works fine but, I would like the table to refresh to get the new results. Here is what I have so far.
function unapprove_link(data)
{
var str = $(this).attr('title');
var answer = confirm("Are you sure you want to UNAPPROVE this lead?");
if (!answer) return false;
$.post("actions/unapprove-lead.php",
{'lead_id': data},
function()
{
oTable.fnClearTable(0);
oTable.fnDraw();
}
);
}
Here is my full code:
$(document).ready(function()
{
/* // Unapprove Lead Alert
$('.unapprove').live('click', function() {
var str = $(this).attr('title');
var answer = confirm("Are you sure you want to UNAPPROVE this lead?");
oTable.fnDraw();
if (!answer) return false;
});
// Delete Lead Alert
$('.delete').live('click', function() {
var str = $(this).attr('title');
var answer = confirm("Are you sure you want to DELETE this lead?");
oTable.fnDraw();
if (!answer) return false;
});
*/
var anOpen = [];
var oTable = $('#example').dataTable
({
'bProcessing': true,
'aaSorting': [[1,'asc']], // sorts date by default.
'iDisplayLength': 10,
'bJQueryUI': true,
'bStateSave': true,
'bServerSide': true,
'sAjaxSource': 'ajax/pc-ajax-table.php',
'fnServerData': function(sSource, aoData, fnCallback)
{
aoData.push( { "name": "from_date", "value": $( "#from" ).val() },
{ "name": "to_date", "value": $( "#to" ).val() } );
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
},
'aoColumns':[
{"bVisible": false, "bSortable": false, "bSearchable": true},
{"fnRender": format_ddmmyyyy}, // renders the date as dd/mm/yyyy
null, // name
null, // lead location
null, // course type
{"bVisible": false, "bSortable": false, "bSearchable": true},
{"bVisible": false, "bSortable": false, "bSearchable": true},
{"bVisible": false, "bSortable": false, "bSearchable": true},
{"bVisible": false, "bSortable": false, "bSearchable": true},
null,
null,
{"sClass": "control", "bSortable": false, "bSearchable": false},
{"bSortable": false, "bSearchable": false},
{"bSortable": false, "bSearchable": false}]
});
// for adding a details box
$('#example td.control').live( 'click', function () {
var nTr = this.parentNode;
var i = $.inArray( nTr, anOpen );
if ( i === -1 ) {
$('img', this).attr( 'src', "../images/details_close.png" );
var nDetailsRow = oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push( nTr );
}
else {
$('img', this).attr( 'src', "../images/details_open.png" );
$('div.innerDetails', $(nTr).next()[0]).slideUp( function () {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
} );
}
} );
function fnFormatDetails( oTable, nTr )
{
var oData = oTable.fnGetData( nTr );
var sOut =
'<div class="innerDetails">'+
'<div style="padding:6px; background-color:#FFF;">Enquiry: <span style="color:#2663A4;">'+oData[8]+'</span></div>'+
'<div style="padding:6px; background-color:#FFF;">Email: <span style="color:#2663A4;">'+oData[5]+'</span></div>'+
'<div style="padding:6px; background-color:#FFF;">Phone: <span style="color:#2663A4;">'+oData[6]+'</span></div>'+
'<div style="padding:6px; background-color:#FFF;">IP Address: <span style="color:#2663A4;">'+oData[7]+'</span></div>'+
'<div style="padding:6px; background-color:#FFF;">Lead ID: <span style="color:#2663A4;">'+oData[0]+'</span></div>'+
'<div style="height:6px;"></div>'+
'<div class="light-blue-underline-main" style="margin:0px;"></div>'+
'<div style="height:6px;"></div>'+
'</div>';
return sOut;
}
// For clicking and selecting the date ranges
$("button").button().click(function() {
oTable.fnDraw();
});
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
// Take date from mysql, formatted yyyy-mm-dd, and return as dd/mm/yyyy
function format_ddmmyyyy(oObj) {
var sValue = oObj.aData[oObj.iDataColumn];
var aDate = sValue.split('-');
return aDate[2] + "/" + aDate[1] + "/" + aDate[0];
}
// Highlight Rows
$("tbody tr").live("mouseover", function(){
$(this).children().addClass("highlighted");
});
$("tbody tr").live("mouseout", function(){
$(this).children().removeClass("highlighted");
});
// Actions for Unapprove button
function unapprove_link(data)
{
var str = $(this).attr('title');
var answer = confirm("Are you sure you want to UNAPPROVE this lead?");
if (!answer) return false;
$.post("actions/unapprove-lead.php",
{"lead_id": data},
function(data)
{
oTable.fnDraw();
}
);
}
/*// Actions for Delete button
function delete_link(data)
{
$.post("actions/delete-lead.php",
{'lead_id': data},
function(data)
{
oTable.fnDraw();
}
);
}
*/

Calling oTable.fnDraw() will cause the refresh for sure. You are doing $.post, I would change it to .$ajax, also, you don't seem to be doing anything with the data returned from the post operation. Remember, DataTable expects an oData object somewhere in the response if you expect it to rebind the data.
In fact, datatable expects a lot more, you need to return the number of items in total, the number being displayed on the page, etc.

Related

Fullcalendar scrolls to top when start dragging

When I start to dragging an event, always scrolls to top of the day (timeGridDay). If I drag and drop when I see, p.e. from 00:00 to 08:00 is ok, but I if I try to drag an event that's at 17:00 then automitically moves to 00:00 -- 08:00 area on the top..
I have another calendar that's working fine... I've compared and it's all the same I think..
Thanks for your help.
var doubleClick = false;
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
height: '700',
plugins: [ 'timeGrid','dayGrid' ,'resourceTimeGrid','interaction'],
titleFormat: {
year: 'numeric',
month: 'numeric',
day: 'numeric'
},
defaultView: 'timeGridDay',
locale: lan,
minTime: '00:00:00',
maxTime: '23:59:00',
allDaySlot: false,
editable: true,
selectable: true,
select: function(info)
{
$('#newEventForm').trigger('reset');
cadenaStr = info.startStr;
cadenaEnd = info.endStr;
datavisita = cadenaStr.substr(0,10);
horainici = cadenaStr.substr(11,8);
horafi = cadenaEnd.substr(11,8);
$('#horastart').val(horainici);
$('#horaend').val(horafi);
$('#data').val(datavisita);
$('#newEventModal').modal('show');
},
droppable: true,
dragScroll: true,
eventResourceEditable: true,
header: {
left: 'prev,next, addEventButton, addReserveButton',
center: 'title',
// right: 'resourceTimeGrid,dayGridMonth,timeGridWeek,timeGridDay'
right: ''
},
views: {
resourceTimeGrid: { buttonText: resbtnname },
//dayGridMonth: { buttonText: 'month' },
//dayGridWeek: { buttonText: 'week' },
//dayGridDay: { buttonText: 'day' }
},
timeZone: 'local',
customButtons: {
addEventButton: {
text: '+',
click: function() {
$('#newEventForm').trigger("reset");
//alert ("passo abans client");
//$('#client').val('').trigger('change');
//$('#pacient').val("");
$('#newEventModal').modal('show');
}
},
addReserveButton: {
text: '||',
click: function() {
$('#newReserveModal').modal('show');
$('#newReserveForm').trigger('reset');
}
}
},
// title: info.event.extendedProps.pacientnom+': '+info.event.extendedProps.description,
// tootlip show up on event mouse hover
dayClick: function(date, jsEvent, view) {
if(!doubleClick) {
doubleClick = true;
setTimeout(function() { doubleClick = false; }, 500); //this waits for a second click for the next 500ms
}
else {
alert ("doble cliiiiikkkk");
//do your double click action here (date and time available in date variable)
}
},
eventRender: function(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
$(info.el).on("mousedown", function(){
tooltip.hide();
});
$(info.el).on("mouseup", function(){
tooltip.hide();
});
$(info.el).on("click", function(){
tooltip.hide();
});
},
// edit form modal show up on event click
eventClick: function(info) {
$('#editsala').empty();
$('#editpacient').empty();
var idvisita = info.event.id;
$('#idvisitaorg').val(idvisita);
$('#visitaForm').submit();
},
// drag and drop event with database records change
eventDrop: function( info ) {
$('.tooltip').hide();
//if (!confirm("Are you sure about this change?")) {
//
// info.revert();
//} else {
var id = info.event.id;
var title = info.event.title;
var timeSettings = { "hour": "2-digit", "minute": "2-digit", "hour12": false };
var starttime = calendar.formatDate(info.event.start, timeSettings);
var endtime = calendar.formatDate(info.event.end, timeSettings);
var startdate =moment(info.event.start).format('YYYY-MM-DD');
if(info.newResource) {
var resourceId = info.newResource.id;
} else {
if(info.oldEvent.extendedProps.Resource_Id){
var resourceId = info.oldEvent.extendedProps.Resource_Id;
} else {
var resourceId =0;
}
}
$.ajax({
url: "calvis_event_dropped_update.php",
type: "POST",
data: ({
id: id,
title: title,
starttime: starttime,
endtime: endtime,
startdate: startdate,
resourceId: resourceId
}),
success: function(data){
calendar.refetchEvents()
},
error: function() {
info.revert();
}
});
//}
},
// resize event with database records change
eventResize: function( info ) {
$('.tooltip').hide();
//if (!confirm("Are you sure about this change?")) {
// info.revert();
//} else {
var id = info.event.id;
var title = info.event.title;
var timeSettings = { "hour": "2-digit", "minute": "2-digit", "hour12": false };
var starttime = calendar.formatDate(info.event.start, timeSettings);
var startdate = moment(info.event.start).format('YYYY-MM-DD');
var endtime = calendar.formatDate(info.event.end, timeSettings);
var resourceId=info.event.extendedProps.Resource_Id;
//console.log(starttime);
//console.log(endtime);
// console.log(info.event.extendedProps.Resource_Id);
$.ajax({
url: "calvis_event_dropped_update.php",
type: "POST",
data: ({
id: id,
title: title,
starttime: starttime,
endtime: endtime,
startdate: startdate,
resourceId: resourceId
}),
success: function(data){
calendar.refetchEvents()
},
error: function() {
info.revert();
}
});
//}
},
//hide select resource for other views
viewSkeletonRender: function(info){
if(info.view.type=="resourceTimeGrid"){
$("#resource_select_div").show();
$("#filter_events_div").hide();
$('#usuario_filter').val('none');
calendar.refetchEvents();
} else{
$("#resource_select_div").hide();
$("#filter_events_div").show();
}
},
// generate events
eventSources: [
{
url: 'calvis_get_events_caltask.php',
method: 'POST',
extraParams: function() {
return {
idusuario: $('#usuario_filter').val()
};
},
failure: function() {
alert('there was an error while fetching events!');
}
}
// any other sources...
],
// generate resources
resources: 'calvis_get_resources.php',
});
//render calendar
calendar.render();

Laravel: DataTable Multiple checkboxes

Im fetching my data in my server side and I put checkbox.
I need some clarification, do I need to put checkbox here or it will be automatically added?
Controller
$result[] = array(
'#' => '<span style="font-size: 12px; color: gray">'.$counter++.'</span>',
'number' => '<p>'.$value->number.'</p>',
'vendor' => '<p>'.$vendor->name .'</p>',
'document_reference' => '<p>'.$value->document_reference.'</p>',
'date_needed' => '<p>'.$value->date_needed.'</p>',
'requesting_department' => '<p>'.$department->name.'</p>',
'amount' => '<p align="right">'.number_format($value->total_amount,2).'</p>',
'status' => '<p>'.$status.'</p>',
'approval_status' => '<p id="'.$value->id.'">'.$approval.'</p>',
'created_by' => '<p id="created_at'.$value->id.'">'.$user->name.'</p>',
'action' => '<i class="fa fa-eye"></i>',
'checkbox' => '<input type="checkbox" name="checkbox[]" value="'.$value->id.'">'
In my view page I used route to call this method. In here I have now my data.
My View
var table3 = $('#get-rfp-for-approval-table').DataTable({
'processing': true,
'serverSide': true,
ajax: {
url: '/requests/request-for-payment/getRFPforApproval',
dataSrc: ''
},
columns: [
{ data: '#' },
{ data: 'number' },
{ data: 'vendor' },
{ data: 'document_reference' },
{ data: 'date_needed' },
{ data: 'requesting_department' },
{ data: 'amount' },
{ data: 'status' },
{ data: 'created_by' },
{ data: 'approval_status' },
{ data: 'action' },
{ data: 'checkbox' },
],
columnDefs: [
{
targets: 11,
checkboxes: {
selectRow: true
}
}
],
select: {
style: 'multi'
},
order: [[1,'desc']]
});
Example I have 15 data, I checked data 5 and data 14. then I submit the form.
My form
if ( $('#approved-selected-form').length > 0 ) {
$('#approved-selected-form').submit(function(e){
var form = this;
var rows_selected = table3.column(0).checkboxes.selected();
// Iterate over all selected checkboxes
$.each(rows_selected, function(index, rowId){
// Create a hidden element
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', 'checkbox[]')
.val(rowId)
);
});
var formData = $(this).serialize();
swal({
title: "Are you sure?",
text: "Transaction will be approved.",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willSave) => {
if (willSave) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
$.ajax({
url: '/requests/request-for-payment/approvedTransaction',
type: "POST",
data: formData,
beforeSend: function() {
var span = document.createElement("span");
span.innerHTML = '<span class="loading-animation">LOADING...</span>';
swal({
content: span,
icon: "warning",
buttons: false,
closeOnClickOutside: false
});
$('.request-for-payment-finish').attr('disabled', 'disabled');
},
success: function(response) {
if (response != '') {
$('#get-request-for-payment-table').DataTable().destroy();
getRequestForPaymentTable();
$('#add-request-for-payment-form').trigger("reset");
swal("Transaction has been saved!", {
icon: "success",
});
setTimeout(
function()
{
window.location.href = "/requests/request-for-payment?id="+response+"#view-request-for-payment-modal";
}, 1500);
}
},
complete: function() {
$('.request-for-payment-finish').removeAttr('disabled');
}
});
} else {
swal("Save Aborted");
}
});
e.preventDefault();
return false;
})
}
NOTE: I tried to dd it in my controller it gives me this
array:1 [
"get-rfp-for-approval-table_length" => "10"
]
I also noticed that in my th, I dont have checkbox(when I clicked this, everything will be checked). Im using this as a guide. https://jsfiddle.net/snqw56dw/3182/.
Question: How can I get those values in my controller?
You should be returning ID in your controller.
$result[] = array(
// ... skipped ...
'checkbox' => $value->id
);
Also since checkbox in column with index 11, you should be using that index when retrieving the data.
var rows_selected = table3.column(11).checkboxes.selected();
On the side note, I see that you're using server-side processing mode ('serverSide': true). Make sure your controller returns proper response.

Datatables : TypeError: dtSettings is undefined

I have implemented data-tables fixed columns on project, the first (patients_report) data-tables report works very well but the second(visitation_report) one fails please advise how can I solve this problem ?
Below is my code :
<script type="text/javascript" src="http://www.datatables.net/release-datatables/media/js/jquery.js"></script>
<script type="text/javascript" src="http://www.datatables.net/release-datatables/media/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="http://www.datatables.net/release-datatables/extensions/FixedColumns/js/dataTables.fixedColumns.js"></script>
<link href='http://www.datatables.net/release-datatables/media/css/jquery.dataTables.css' rel='stylesheet'>
<link href='http://www.datatables.net/release-datatables/extensions/FixedColumns/css/dataTables.fixedColumns.css' rel='stylesheet'>
<script type="text/javascript">
var j = jQuery.noConflict();
j(document).ready(function () {
j(document).ready(function () {
var table = j('.patients_report').DataTable({
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false
});
new j.fn.dataTable.FixedColumns(table, {
leftColumns: 0,
rightColumns: 1
});
fc.fnUpdate();
});
j(document).ready(function () {
var visitation_table = j('.visitation_report').DataTable({
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false
});
new j.fn.dataTable.FixedColumns(visitation_table, {
leftColumns: 0,
rightColumns: 1
});
fc.fnUpdate();
});
j('.edit_patient_link').click(function () {
//get data
var patient_id = j(this).closest('tr').find('input[name="view_patient_id"]').val();
j.ajax({
type: "GET",
url: "<?php echo base_url(); ?>reports/get_patient_reports_details/" + patient_id,
dataType: "json",
success: function (response) {
j('#edit_patient_id').val(response[0].patient_id);
j('#edit_title').val(response[0].title);
j('#edit_phone_no').val(response[0].phone_no);
j('#edit_inputFirstName').val(response[0].f_name);
j('#edit_inputSurName').val(response[0].s_name);
j('#edit_inputOtherName').val(response[0].other_name);
j('#edit_dob').val(response[0].dob);
j('#edit_gender').val(response[0].gender);
j('#edit_maritalstatus').val(response[0].marital_status);
j('#edit_nationalid').val(response[0].identification_number);
j('#edit_email').val(response[0].email);
j('#edit_address').val(response[0].address);
j('#edit_residence').val(response[0].residence);
j('#edit_employement_status').val(response[0].employment_status);
j('#edit_employers_name').val(response[0].employer);
j('#edit_kinname').val(response[0].next_of_kin_fname);
j('#edit_kinsname').val(response[0].next_of_kin_lname);
j('#edit_kinrelation').val(response[0].next_of_kin_relation);
j('#edit_kinphone').val(response[0].next_of_kin_phone);
j('#edit_family_number').val(response[0].family_base_number);
},
error: function (data) {
}
});
});
j('.view_patient_link').click(function () {
//get data
var patient_id = j(this).closest('tr').find('input[name="view_patient_id"]').val();
j.ajax({
type: "GET",
url: "<?php echo base_url(); ?>reports/get_patient_reports_details/" + patient_id,
dataType: "json",
success: function (response) {
j('#view_patient_id').val(response[0].patient_id);
j('#view_title').val(response[0].title);
j('#view_phone_no').val(response[0].phone_no);
j('#view_inputFirstName').val(response[0].f_name);
j('#view_inputSurName').val(response[0].s_name);
j('#view_inputOtherName').val(response[0].other_name);
j('#view_dob').val(response[0].dob);
j('#view_gender').val(response[0].gender);
j('#view_maritalstatus').val(response[0].marital_status);
j('#view_nationalid').val(response[0].identification_number);
j('#view_email').val(response[0].email);
j('#view_residence').val(response[0].residence);
j('#view_employement_status').val(response[0].employment_status);
j('#view_employers_name').val(response[0].employer);
j('#view_kinname').val(response[0].next_of_kin_fname);
j('#view_kinsname').val(response[0].next_of_kin_lname);
j('#view_kinrelation').val(response[0].next_of_kin_relation);
j('#view_kinphone').val(response[0].next_of_kin_phone);
j('#view_family_number').val(response[0].family_base_number);
},
error: function (data) {
}
});
});
j('.delete_patient_link').click(function () {
//get data
var patient_id = j(this).closest('tr').find('input[name="view_patient_id"]').val();
j('.input_patient_id_delete').val(patient_id);
});
});
</script>
<style>
/* Ensure that the demo table scrolls */
th, td { white-space: nowrap; }
div.dataTables_wrapper {
width: 1000px;
margin: 0 auto;
}
</style>
I can't see clearly what is the problem with your code. But I assume that is in first part, so put everything in single document ready event. Like this :
j(document).ready(function () {
var table = j('.patients_report').DataTable({
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false
});
new j.fn.dataTable.FixedColumns(table, {
leftColumns: 0,
rightColumns: 1
});
table.fnUpdate();
var visitation_table = j('.visitation_report').DataTable({
scrollY: "300px",
scrollX: true,
scrollCollapse: true,
paging: false
});
new j.fn.dataTable.FixedColumns(visitation_table, {
leftColumns: 0,
rightColumns: 1
});
visitation_table.fnUpdate();
// rest of code
...
}); // close document ready event callback
There is fc.fnUpdate(); but I can't find fc variable nowhere. That should have been dataTable object. I hope this will do the trick. Good luck with project.

create datatables jquery dynamically with parameter from query

I use "datatables plugin for jquery" to display the results of a query in mysql.
The user can also select from a dropdown list (dateParam) and a multiselect values (conseiller) that will automatically restrict the results of the query and thus modify the table. Instead of having 5 columns, I have only 3 for example.
This is where I get the following error alert: "... requested unknown parameter 'data.1' (for example) for row 0...".
json result without selecting:
[{"name":"CONSEILLER","data":["cons1","cons2","cons3","TOTAL UNITES"]},{"name":"TOTAL UNITES","data":[1,9,2,12]}]
json result if I select some parameters:
[{"name":"CONSEILLER","data":["cons2","TOTAL UNITES"]},{"name":"TOTAL UNITES","data":[9,9]}]
Here a part of my query :
<?php
include("../dbconfig.php");
if (isset($_GET["dateParam"],$_GET["dateParam2"],$_GET["conseiller"])) {
$SQL = "
...the query...
";
$result = $dbh->prepare($SQL);
$result->execute();
} else {
$SQL = "
...the query....
";
$result = $dbh->prepare($SQL);
$result->execute();
}
$rows = array();
$rows['name'] = 'CONSEILLER';
$rows1 = array();
$rows1['name'] = 'TOTAL UNITES';
while($row = $result->fetch()) {
$rows['data'][] = $row['CONSEILLER'];
$rows1['data'][] = ($row['UNITES']);
}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);
header('Content-type: application/json');
print json_encode($result, JSON_NUMERIC_CHECK); // VERSION PHP >= 5.3.3
?>
Here is a part of my js :
$(document).ready(function() {
var table = $('#dt_actions_rae_conseiller').DataTable({
"paging": false,
"searching": false,
"bInfo": false,
"scrollX": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxDataProp": "",
"sAjaxSource": "../query/query_actions_rae_conseiller_dt.php",
"aoColumns": [
{ "data": "name" },
{ "data": "data.0" },
{ "data": "data.1" },
{ "data": "data.2" },
{ "data": "data.3" },
],
});
});
/**
* Datepicker
*/
$(function() {
var dateParam = "";
$( "#datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
showAnim: 'drop',
//showOn: "button",
//buttonImage: "../icones/calendar.gif",
//buttonImageOnly: true,
onSelect: function(date){
dateParam = date;
}
});
var dateParam2 = "";
$( "#datepicker2" ).datepicker({
dateFormat: "yy-mm-dd",
showAnim: 'drop',
//showOn: "button",
//buttonImage: "../icones/calendar.gif",
//buttonImageOnly: true,
onSelect: function(date){
dateParam2 = date;
}
});
});
/**
* Multiselect
*/
$(function(){
$("#conseiller").multiselect({
//header: 'Choisir conseillers',
minWidth: 160,
checkAllText: 'all',
uncheckAllText: 'no',
noneSelectedText: 'Conseiller',
selectedList: 7,
/* selectedText: function(numChecked, numTotal, checkedItems){
return numChecked + ' of ' + numTotal + ' checked';
}, */
show: ["bounce", 200],
hide: ["explode", 1000]
});
//$('#projet').bind('change', function() {alert('Change'); });
});
/**
* Button
*/
$(function(){
$('button').click(function() {
var d1 = $("#datepicker").val();
var d2 = $("#datepicker2").val();
var d3 = $("#conseiller").val().join(",");
$.ajax({
url: "../query/query_actions_rae_conseiller_dt.php",
//data: {dateParam:d1, dateParam2:d2},
type: "get",
dataType: "json",
success: function(json){
table = $('#dt_actions_rae_conseiller')
.on('preXhr.dt', function ( e, settings, data ) {
data.dateParam = d1
data.dateParam2 = d2
data.conseiller = d3
})
.DataTable({
"destroy": true, // TO REINITIALISE DATATABLE
"paging": false,
"searching": false,
"bInfo": false,
"scrollX": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxDataProp": "",
"sAjaxSource": "../query/query_actions_rae_conseiller_dt.php",
"aoColumns": [
{ "data": "name" },
{ "data": "data.0" },
{ "data": "data.1" },
{ "data": "data.2" },
{ "data": "data.3" },
],
});
} // end ajax function
}); // end ajax
}); // end click function
}); // end function
and my php:
<table id="dt_actions_rae_conseiller" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead> // not needed ?
<tr> // not needed ?
<th></th> // not needed ?
<th></th> // not needed ?
<th></th> // not needed ?
<th></th> // not needed ?
<th></th> // not needed ?
</tr> // not needed ?
</thead> // not needed ?
</table>
Thnaks for all !
Ahem, as Php . net says is not sure to test it whit a rowcount -> http://php.net/manual/en/pdostatement.rowcount.php
Because most databases won't return the number of rows.
Instead you can first run a query A with a count(*) then use a fetchColumn to have in a var the number of rows that will be obtained and then do your loop only if count > 0

fullCalendar displaying everything as allDay

I have created a calendar that saves to MySQL.
I have the allDay value set as false for time frame events but the calendar displays it as all day.
This gets the events..
$sql = mysql_query('SELECT * FROM `companies`.`calendar`');
${'Events'} = array();
while(${'Event'} = mysql_fetch_assoc($sql)){
${'Events'}[] = ${'Event'};
}
Snapshot of my table:
Here is my jQuery
$(document).ready(function() {
$('#eventToAdd').dialog({
autoOpen: false,
height: '300',
width: '550',
modal: true,
resizable: false,
position: 'center',
});
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
},
eventClick: function(calEvent, jsEvent, view) {
$('#eventTitle').val(calEvent.title);
$('#textColor').val(calEvent.textColor);
$('#backgroundColor').val(calEvent.color);
$("#eventToAdd").dialog({
autoOpen: true,
title: "Update Event",
modal: true,
buttons: [
{
text:"Update Event",
click: function () {
if($('#eventTitle').val()){
calEvent.title = $('#eventTitle').val();
calEvent.color = $('#backgroundColor').val();
calEvent.textColor = $('#textColor').val();
calendar.fullCalendar('updateEvent',calEvent);
$.post('post.api.php', { 'api': 'updateEvent', 'id': calEvent.id, 'title': calEvent.title, 'start': $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd h:mm:ss tt'), 'end': $.fullCalendar.formatDate(calEvent.end, 'yyyy-MM-dd h:mm:ss tt'), 'allDay': calEvent.allDay, 'bgColor': calEvent.color, 'textColor': calEvent.textColor }, function(resp) {
if(resp == 'SUCCESS') {
jAlert('The event has been updated','Updated');
} else {
jAlert('There was an error updating the event<br />Please try again later.<br />ERROR CODE: 728375', 'Process Error');
}
$('#eventToAdd').dialog('close');
});
}
}
},
{
text: "Cancel",
click: function() { $(this).dialog('close'); }
}]
});
},
selectable: true,
selectHelper: true,
select: function (start, end, allDay, jsEvent, view) {
$("#eventToAdd").dialog(
{
autoOpen: true,
title: "Create Event",
modal: true,
buttons: [
{
text:"Create Event",
click: function () {
if($('#eventTitle').val()){
calendar.fullCalendar('renderEvent',
{
title: $('#eventTitle').val(),
start: $.fullCalendar.formatDate(start, 'yyyy-MM-dd h:mm:ss tt'),
end: $.fullCalendar.formatDate(end, 'yyyy-MM-dd h:mm:ss tt'),
allDay: allDay,
textColor: $('#textColor').val(),
color: $('#backgroundColor').val()
},
true
);
var startDate = $.fullCalendar.formatDate(start, 'yyyy-MM-dd h:mm:ss tt');
var endDate = $.fullCalendar.formatDate(end, 'yyyy-MM-dd h:mm:ss tt');
$.post('post.api.php', { 'api': 'createEvent', 'title': $('#eventTitle').val(), 'start': startDate, 'end': endDate, 'allDay': allDay, 'textColor': $('#textColor').val(), 'bgColor': $('#backgroundColor').val() }, function(response) {
if(response == 'SUCCESS'){
jAlert('The event has been saved!','Event Created');
} else {
jAlert('There was an error saving your event<br />Please try again later or let JD know<br />ERROR CODE: 882293','Process Error');
}
});
}
$(this).dialog('close');
}
},
{
text: "Cancel",
click: function() { $(this).dialog('close'); }
}
],
close: function(){
$('#eventTitle').val('');
$('#textColor').val('');
$('#backgroundColor').val('');
}
});
},
editable: true,
events: <?= ${'Events'}; ?>
});
});
The record value should be returned as false (without quotes); not "false". I had the same problem and applied this simple solution:
// -----------------------
while ($row = mysql_fetch_assoc($sql)) {
// -----------------------
if ($row['event_allday'] = 'false') {
$allDayStatus = false;
}
// -----------------------
$eventsArray['id'] = $row['event_id'];
$eventsArray['title'] = $row['event_title'];
$eventsArray['start'] = $row['event_start'];
$eventsArray['end'] = $row['event_end'];
$eventsArray['url'] = $row['event_url'];
$eventsArray['allDay'] = $allDayStatus;
$eventsArray['className'] = $row['event_class'];
$eventsArray['admNotes'] = $row['event_adm_notes'];
// -----------------------

Categories