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

Cannot implicitly convert type 'string' to 'DayPilot.Web.Mvc.Events.Gantt.RowClickHandlingType'

Asked by William Clark
8 years ago.

I have a Gantt populated with data and I want to allow the user to click on a row and load another view to perform actions pertaining to the event.

There is little to no real documentation--or at least no examples--on how to use RowClickHandling for a Gantt, and it doesn't appear to work the same way it is suggested to for the scheduler (https://doc.daypilot.org/scheduler/row-selecting/).

When I use RowClickHandling = "Select", I get the error above. On checking the definition for the RowClickHandlingType, I see it has:

//
// Summary:
// Enabled. Only the client-side event handlers will be fired.
Enabled = 0,
//
// Summary:
// The user action will call an AJAX CallBack event.
CallBack = 1,
//
// Summary:
// This functionality is disabled at all.
Disabled = 2

Enabled doesn't work either, in fact nothing appears to work. It also seems backwards to say Enabled is zero.

So is this supposed to work? And is it what I'm looking for?

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

There is now a new guide on row selecting available in the documentation:

http://doc.daypilot.org/gantt/row-selecting/

The latest sandbox build (8.1.5816) fixes a few related issues (such as the missing RowClickHandling = DayPilot.Web.Mvc.Events.Gantt.RowClickHandlingType.Select option).

There is also a demo available in the sanbox (the source is available in the download package):

http://mvc.daypilot.org/sandbox/Gantt/RowSelecting

Comment posted by William Clark
8 years ago.

The source doesn't seem to exist in the download package. Is the sandbox trial version full featured? When will we see a production version ready?

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

You need to download it directly in the sandbox, using the "Download" button in the upper-left corner. Here is a direct link:

http://mvc.daypilot.org/sandbox/DayPilotProMvcTrial-8.1.5816.zip

The sandbox version is a development build (and it's a trial). Usually it's stable but it's not guaranteed. This particular version is stable.

The next release is 8.2 and it is planned to be released by the end of February.

Comment posted by William Clark
8 years ago.

I did download from there. I don't see a source folder.

I get the stable part, and don't doubt it is. But my impression is that there were things missing from the trial--things I was planning on taking advantage of.

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

It includes the source code of the demo project. You can find it in "Demo" directory. The "Row Selecting" view can be found at Demo/Views/Gantt/RowSelecting.cshtml.

The trial version includes all the feature that the full version does - it just displays the "DEMO" label. And of course it doesn't include the source code of the control.

What exactly were you looking for? Maybe I could help.

Comment posted by William Clark
8 years ago.

Okay, some confusion there on the source. Makes sense. I was only concerned about the trial not being full featured so if, as you say, it is then the full source would not be necessary. Thanks for your attention.

Comment posted by William Clark
8 years ago.

Here is what I get after placing the DLL and script into the project: (I confirmed the JavaScript has version 2042)

System.Exception was unhandled by user code
HResult=-2146233088
Message=Incompatible DayPilot client script version. Expected 2042 (you are using 1944).
Source=DayPilot.Web.Mvc
StackTrace:
at DayPilot.Web.Mvc.Utils.Version.Check(String version)
at DayPilot.Web.Mvc.DayPilotGantt.CallBack(Controller c)
at RAM.Controllers.MissionController.Backend() in C:\Users\wclark.IDIVAFB\Source\Workspaces\Workspace\RAM\RAM\Controllers\MissionController.cs:line 14
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
InnerException:

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

It looks like the old version of daypilot-all.min.js might still be cached somewhere... Let me know if Ctrl-F5 doesn't help.

Comment posted by William Clark
8 years ago.

Got it. Given that my skills are not all that, I hope I don't irritate you with all this.

I see that DayPilot.Web.Mvc.Events.Gantt.RowClickHandlingType.CallBack is going to call back to my controller's ActionResult RowSelecting() method. I don't see anything related to where I can find details of the data in the row that was clicked. TaskClickArgs looks like it would have what I need. Am I correct that I can look there once the row has been clicked/selected?

I was presuming that I could grab the database table ID from the row that was clicked on and pass it to another view.

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

No problem, I'm glad that it's working.

> I see that DayPilot.Web.Mvc.Events.Gantt.RowClickHandlingType.CallBack is going to call back to my controller's ActionResult RowSelecting() method.

If you use "CallBack" event handling type it will fire the server side event. However, it doesn't call RowSelecting() method (that's the method that displays the /Gantt/RowSelecting demo). All CallBacks use an AJAX request to the URL specified using BackendUrl property of the calendar.

Example:

MVC View
@Html.DayPilotGantt("gantt", new DayPilotGanttConfig {
    BackendUrl = Url.Action("Backend", "Gantt"),
    // ...
    RowClickHandling = DayPilot.Web.Mvc.Events.Gantt.RowClickHandlingType.CallBack,
    RowClickJavaScript = "window.console && console.log(args);"
})

BackendUrl points to Gantt/Backend (public ActionResult Backend() method) which redirects the processing to the Gantt class.

The events are then handled by the respective method override. In this example, it is OnRowClick. This name is fixed (you need to override the method defined in DayPilotGantt class, the parent of Gantt):

MVC Controller
using System;
using System.Web.Mvc;
using DayPilot.Web.Mvc;
using DayPilot.Web.Mvc.Events.Gantt;
using DayPilot.Web.Mvc.Json;

namespace MvcApplication1.Controllers
{
    [HandleError]
    public class GanttController : Controller
    {

        public ActionResult RowClicking()
        {
            return View();
        }


        public ActionResult Backend()
        {
            return new Gantt().CallBack(this);
        }


        class Gantt : DayPilotGantt
        {
            protected override void OnInit(InitArgs e)
            {
                Tasks = new TaskManager(Controller, "default").TaskData;
                Links = new TaskManager(Controller).LinkData;                

                ScrollTo(DateTime.Today);
                UpdateWithMessage("Welcome!");
            }

            protected override void OnRowClick(RowClickArgs e)
            {
                Redirect("~/Gantt/RowSelecting");
            }

        }

    }
}

You can use this method (OnRowClick) to process the event. In this case, it redirects the user to a new URL.

You can also do the redirect on the client side - see both examples in the new "Row Clicking" doc page:
http://doc.daypilot.org/gantt/row-clicking/

This example is now also available in the latest sandbox build (8.1.5818):
http://mvc.daypilot.org/sandbox/Gantt/RowClicking

Comment posted by William Clark
8 years ago.

I hesitate to do much client side out of security concerns. The problem is that since overriding OnRowClick() requires it to be protected, it is a static method and Redirect() is not accessible directly (neither is Session()). I've struggled with this all day and cannot see a way to get it to do a redirect. Here is my code:

protected override void OnRowClick( DayPilot.Web.Mvc.Events.Gantt.RowClickArgs e)
{
string selectedID = e.Task.Id;
Session["selectedID"] = selectedID;
Redirect("~/Schedule/MissionDetail");
}

And here are the errors:

Error CS0120 An object reference is required for the non-static field, method, or property 'Controller.Session'

Error CS0120 An object reference is required for the non-static field, method, or property Controller.Redirect(string)'

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

The OnRowClick() method is inside the Gantt class, i.e. it has access to its parent (DayPilotGantt) methods but not to Controller methods.

DayPilotGantt.Redirect() is available since build 8.1.5818 (you're probably working with an earlier version, that's why it doesn't recognize the Redirect() call).

If you want to access the controller members (e.g. Session) you can do it using DayPilotGantt.Controller property:

protected override void OnRowClick( DayPilot.Web.Mvc.Events.Gantt.RowClickArgs e) 
{ 
string selectedID = e.Task.Id; 
Controller.Session["selectedID"] = selectedID; 
Redirect("~/Schedule/MissionDetail"); 
}

You can reach the Controller.Redirect() this way as well but it won't work - the OnRowClick is called from a special request (CallBack) which expects a JSON result (generated automatically by DayPilotGantt). If you call Controller.Redirect() the callback will fail.

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