Jquery fullCalendar filter events and can't render the filtered events - jquery-plugins

This is my first time asking a question here. I am using the jQuery plugin fullCalendar and for the most part I have it working great with exception of one problem. I have added a filter to the calendar events where when a user clicks on a checkbox, I want to reload the calendar and query a database to get the filtered results. I am able to do this without problems but, if I am on a month that is not the current month, the calendar will always go back to the current month with the filtered results. The user would then have to click on the prev/next buttons to get back the that they were on.
One solution that seems to work up to a point is this:
function reloadCalendar(formInputs, height, view, startView, endView) {
var source1 = {
url: 'ajax.php?c=careerDevCalendar&a=getEvents',
data: {
filter: formInputs
}
};
var s = Math.round(startView.getTime() / 1000);
var e = Math.round(endView.getTime() / 1000);
var source = 'ajax.php?c=careerDevCalendar&a=getEvents&startF='+s+'&endF='+e+'&'+formInputs;
$("#calendar").fullCalendar('removeEvents');
$("#calendar").fullCalendar('removeEventSource', source1);
$("#calendar").fullCalendar('addEventSource', source);
$("#calendar").fullCalendar('rerenderEvents');
}
I am able to get the filtered results in a JSON array and the calendar stays on the month that I happen to be on, but it won't render the events in the calendar. Does anybody have any ideas on what I can do to filter events without having the calendar go back to the current month?
Thanks in advance

Related

DHTMLX Scheduler Month View only event count

1) In month view events are visible, instead of those events I want to show the counts only. How this can be achieved in DHTMLX Scheduler JS version.
2) Enable date area click event in month view, not the event_link which directs to day or week view. Just need an event when In month view a date box is clicked I have to load events of that day only on click.
It can be implemented using scheduler.addMarkedTimespan() method. You need to iterate all days during the month, count events for each day by scheduler.getEvents() and then specify the result in the html parameter of addMarkedTimespan.
function addEvCount(){
var startDate = scheduler.getState().min_date;
var endMonthDate = scheduler.getState().max_date;
while(startDate.getTime() < endMonthDate.getTime()){
var endDayDate = scheduler.date.add(startDate, 1, 'day');
var evs = scheduler.getEvents(startDate, endDayDate);
if(evs.length){
scheduler.addMarkedTimespan({
start_date: startDate,
end_date: endDayDate,
html:"<div style='text-align:center;'><b>"+evs.length+"</b></div>",
css: "color"
});
}
startDate = endDayDate;
}
scheduler.updateView();
}
Please check how it works in the snippet.
To hide all events, use also Filtering Events.
scheduler.filter_month = function(id, event){
return false; // event will not be rendered
}
The updated demo only with numbers and without rendered events.
Related docs: addMarkedTimespan(), getEvents(), Filtering.
There is onEmptyClick event which fires when the user clicks on an empty space in the scheduler (not on events). Demo.

DHTMLX Scheduler timeline click on day_date

In a scheduler timeline view having a second_scale, is it possible to click on a single date? I have found this answer, but I'm wondering if there is an event in the meantime.
There are onXScaleClick, onXScaleDblClick events for the Timeline view. But in case, when you have 2 scales, they fire only for the second one. Check console in the snippet that demonstrates it.
Nonetheless, you can add onclick event listener for the first scale using js:
var dateScaleEl = document.querySelector(".dhx_second_scale_bar");
dateScaleEl.onclick = function() {
var targetDate = scheduler.getState().date;
console.log(targetDate);
}
Demo.
getState() is a method to get the active date.

Fullcalendar Problems w/ filtering Events in agendaDay-View (works only one time, then no more events exist)

I have a problem with filtering events:
I use fullcalender in agendaDay-View
I use a drop-Down list to select a driver
I compare the name (it is a property of event-object) with the selected value
(this part is ok)
Then,
I remove all Events (.fullCalendar('removeEvents');)
Add the specific events
(add with renderEvents doesn't work proberly at the moment)
And now my problem appears:
For the first time it works, however, when I select another 'driver', the events are gone, because of the 'removeEvents'-Action before.
So, how can I solve this problem, that I can only display the filtered events and keep the other (actualley all events) to filter again for second, third n- time?
$('#' + id).fullCalendar('refetchEvents');
was the first idea, however, its brings all back and selected Issues were doubled (and so on).
I'm thankful for every hint.
Ok I think you can solve your problem with fullCalendar's eventRender function.
The function can also return false to completely cancel the rendering of the event.
Your event from events.json should have a property like 'driver_id'.
I would have select field instead of dropdown with option keys being driver ids, values - names or whatever. Lets say it's id would be 'driver_select'.
Then render events like this:
$('#calendar').fullCalendar({
//...
eventRender: function(event, element) {
//driver select should have default value assigned or else no events will be rendered
if ($("#driver_select").val() !== event.driver_id) {
return false; //do not render other driver events
}
}
//...
});
Handle select changes to update
$("#driver_select").off('change').on('change', function() {
$("#calendar").fullCalendar( 'refetchEvents' );
});
Another approach would be to show all drivers in a timeline. For that you can use FullCalendar Scheduler.

Handle ajax response with node.js

I am trying to scrape information from a specified website. This site uses authentication first, thus a i use zombie.js:
var Browser = require("zombie");
var browser = new Browser();
browser.visit("https://*****login.aspx", function(){
browser.fill('#user', '*****');
browser.fill('#pwd', '*****');
var button = browser.querySelector('#btnSubmit');
browser.fire('click', button, function(){
//scraping main.aspx
});
});
It's working, i can scrape the main.aspx: there is a <table>, containig information about new messages(from, date, subject,), the problems comes here: the subject field is clickable, and clicking on it makes a new window appear with the actual message. However it is an ajaxgrid, and when i perform a click:
var field = browser.querySelector('#VeryLongIdOfTheField');
browser.fire('click', field, function(){
console.log(browser.querySelector('#VeryLongIdOfTheFieldContainingTheMessage').innerHTML);
});
it returns an error message, saying that undefined has no innerHTML. I suppose its because this action handled with some ajax magic. I am new in this js/nodejs/jquery/.. world, some help needed to enlight me.
Since the data is populated using async ajax, I'm guessing there's a lag between your click and the actual DOM population inside the node. How about waiting for a bit before checking the content inside the node.
browser.fire('click', field, function(){
setTimeout(function(){
console.log(browser.querySelector('#VeryLongIdOfTheFieldContainingTheMessage').innerHTML);
}, 3000)
});
If the time taken is not very predictable, you could also run it inside a loop until you find the content or exit after a reasonable number of retries.

YUI DataTable Button events lost after filtering

I'm using a YUI2 DataTable.
Some of the rows of the tables have an icon button that when clicked on will popup additional details for the row.
I'm doing the following to define the panel which gets displayed with the additional information:
MyContainer.panel2 = new YAHOO.widget.Panel("popupPanel2",
{ width:"650px", visible:false, constraintoviewport:true, overflow:"auto" } );
MyContainer.panel2.render();
YAHOO.util.Event.addListener("showButton2", "click",
MyContainer.panel2.show, MyContainer.panel2, true);
So, everything works well with that. Then I added a button that when clicked on filters out some of the rows.
MyContainer.oPushButton1.onclick = function onButtonClickp(p_oEvent)
{
var filter_val = "xxx";
myDataTable.getDataSource().sendRequest(filter_val,
{success: myDataTable.onDataReturnInitializeTable},myDataTable);
}
This filters and redraws the table. But after doing that, the buttons on the remaining rows that should popup a panel no longer work.
Nothing happens when I click on the buttons.
I'm sure I've done something wrong, but I don't know what. The buttons and panels with the correct id's still seem to be available on the page.
Do I somehow have to re-enable the listener for the click event after the datatable redraw? I'm not sure where to look for trying to debug the failed listener.
I got this working by making a call to addListener again after resetting the data for the Datasource.
MyContainer.oPushButton1.onclick = function onButtonClickp(p_oEvent)
{
var filter_val = "xxx";
myDataTable.getDataSource().sendRequest(filter_val,
{success: myDataTable.onDataReturnInitializeTable},myDataTable);
YAHOO.util.Event.addListener("showButton2", "click",
MyContainer.panel2.show, MyContainer.panel2, true);
}

Resources