search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Apply filtering on "OnInit()" function

Asked by Antonio
6 years ago.

Hi i would apply a filter on initial daypilot calendar but aniting change on thw view. I'm using this code add in "OnInit()" function:

Events = From ev In dc.Events Where ev.Risorsa = "Operatorexxxx" Select ev

UpdateWithMessage("Benvenuto!", CallBackUpdateType.Full)

Can anyone helpme please?!! thanks

Answer posted by Dan Letecky [DayPilot]
6 years ago.

This will work fine - just make sure you don't overwrite Events in OnFinish(). OnFinish() is called at the end of every CallBack request.

Comment posted by Antonio
6 years ago.

Hi, thanks for answer...
I overwrite too event OnFinish()... so i have to insert the following code only in OnFinish()?
"Events = From ev In dc.Events Where ev.Risorsa = "Operatorexxxx" Select ev"

Comment posted by Dan Letecky [DayPilot]
6 years ago.

That depends on the logic.

If you use "CallBack" event handling type (e.g. EventMoveHandling=CallBack) then you need to reload all events at the end of the callback (to make sure fresh data is loaded). In that case OnFinish is handy so you don't have to repeat the loading in every event handler (OnEventMove, OnEventResize, etc.).

For "Notify" event handling type it's not necessary to reload them (the Scheduler is updated on the client side before calling the server). In this case it's enough to load events just once, in OnInit().

So: If you are using "CallBack" handling and always load the data using the same filter you can move it to OnFinish.

Comment posted by Antonio
6 years ago.

I'm using callback event and as you wrote each time is invoked onFinish function.
Now i need to pass a parameter to onFinish method.
How can i do?
Thanks

Comment posted by Dan Letecky [DayPilot]
6 years ago.

As you can see the controller action creates a new instance of Dpc class for every request. So you can use a standard member of Dpc class to store parameters that need to be passed from OnInit() to OnFinish().

You can also set it in Backend() method before calling CallBack if you want to pass a parameter from the controller to the calendar backend class.


public class CalendarController : Controller
{
    public ActionResult Backend()
    {
        return new Dpc().CallBack(this);
    }
   
    //...
}


public class Dpc : DayPilotCalendar
{

    string myVal;

    protected override void OnInit(InitArgs initArgs)
    {
      myVal = "test";
    }

    protected override void OnFinish()
    {
      string receivedFromOnInit = myVal;
    }

}
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.