Binding to custom editor for a grid column (i.e. drop down list)

7 posts, 0 answers
  1. Paul
    Paul avatar
    3 posts
    Member since:
    Jan 2011

    Posted 13 Jun 2012 Link to this post

    How do you specify a custom editor function for in-line editing with ASP.NET MVC?  If I was doing this strictly on the client side I would set the 'editor:' attribute on the column with a javascript function name.  Is there a way to specify an editor function using Razor syntax in my view?

    FYI, the scenario here is very simple - I have a list of Products and each product record has a Category ID field.  When I add or edit a product, I want the user to select from a list of defined categories.  The category items can come from server on initial page load or dynamically from ajax (in this case, I really don't care which - the category list doesn't change much).

    Thanks in advance.
  2. Yawar
    Yawar avatar
    1 posts
    Member since:
    Apr 2011

    Posted 07 Jul 2012 Link to this post

    exactly what I am trying to do but I am unable to do it. Did you get any response for this?
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Paul
    Paul avatar
    3 posts
    Member since:
    Jan 2011

    Posted 08 Jul 2012 Link to this post

    Found a hacky sort of work-around buy attaching the custom editor client-side after the grid is created.  I included the following javascript function as part of the <script> tag in the view (after the grid is defined)...

            $(function() { 
                var grid = $("#Grid").data("kendoGrid");
                var col = grid.columns[0];
                col.editor = categoryDropDownEditor; // attach custom editor function to column
            });

    Then I created the custom editor function in a stand-along .js file for this page so I could use the VS debugger on it.  I bit of a kludge, but it does work.  I'd still like to see a better server-side solution on this.

    -Paul
  5. Atlas
    Atlas avatar
    97 posts
    Member since:
    Jun 2009

    Posted 12 Jul 2013 Link to this post

    I thought the kendo forums were supposed to be premium forums?
    Hey Telerik, can you respond to this issue?
  6. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 17 Jul 2013 Link to this post

    Hello,

    The MVC Grid uses the MVC EditorTemplates and currently does not support setting a JavaScript function. If you believe that this functionality should be added then I can suggest to create a feature request in our user voice forum so we can track its interest.

    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  7. loi
    loi avatar
    25 posts
    Member since:
    Feb 2010

    Posted 20 Sep 2013 Link to this post

    I needed to do something similar, and setting the column editor javascript name is still not supported right now. Added a request for this feature.
    http://feedback.kendoui.com/forums/127393-kendo-ui-feedback/suggestions/4459400-setting-the-mvc-grid-column-editor-javascript-func
  8. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 19 Mar 2015 Link to this post

    One good reason this is need is so you can have standard HTML inputs, elements, etc. in your editor, and not just a single Kendo MVC widget.  I tried putting standard HTML (couple of checkboxes and some span elements) inside a MVC Editor-template, but there's 2 main problems:
    (1) when you click anything other than the checkbox (the span element, or other text) the editor is automatically closed.
    (2) the grid's "save" event is not fired when the editor is closed (where you could manually update the model).  This can be fixed by having an "apply" button/span that the user clicks inside your editor and you can get the row's data-item model, but clicking around in the editor causes the editor to close.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready