Use different editors based on the column values of an item

6 posts, 0 answers
  1. Hamza
    Hamza avatar
    14 posts
    Member since:
    Oct 2017

    Posted 31 Jul 2018 Link to this post

    Hi everyone,

     

    I have a RadGrid with batchedit mode in a usercontrol, and I want to have different editors based on the type of the parameter. For example : if the parameter is a string, the editor should allow to write strings, or datetime, boolean, integer, even files so the user can download the file and also images so they can appear on the radgrid !

    I found something similar to what I want but it's using Kendo UI : https://docs.telerik.com/kendo-ui/knowledge-base/grid-different-editor-based-on-column-value

    Any suggestions ?

     

    Thank you

  2. Vessy
    Admin
    Vessy avatar
    2301 posts

    Posted 31 Jul 2018 Link to this post

    Hi Hamza,

    You can achieve the target behavior utilizing the EditForm Template functionality of RadGrid. A live demo demonstrating this can be found here:
    https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

    Regards,
    Vessy
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Hamza
    Hamza avatar
    14 posts
    Member since:
    Oct 2017

    Posted 31 Jul 2018 in reply to Vessy Link to this post

    Hi Vessy,

     

    The problem is that I am using BatchEdit RadGrid  : https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx. And it is actually my user control, so I don't really know how I can use the EditForm Template depending on my "Type" of my object parameter.

     

    I'll show you an image so it can be more clear. I'm trying to have exactly the same comportment in the link that I sent in my first post !

    In my picture : The parameter "Integer" should allow user to enter only numeric numbers, the "string" one should allow to write exactly only strings and so on for other types..

    Regards.

    Thank you !

  4. Vessy
    Admin
    Vessy avatar
    2301 posts

    Posted 02 Aug 2018 Link to this post

    Hi Hamza,

    The behavior shown in the link is actually the default behavior of the Batch edit mode of the Grid - each column is edited depending on its DataType. You can test this behavior in our online demos as well:
    https://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx

    In case the default behavior of the Grid does not fit your needs, you can handle the Gird's CreateColumnEditor event and set the desired Editor type manually in it. You can find useful information on this matter here:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/grid-editors/custom-editors-extending-auto-generated-editors#using-the-createcolumneditor-event
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/grid-editors/auto-generated-editors

    Regards,
    Vessy
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Hamza
    Hamza avatar
    14 posts
    Member since:
    Oct 2017

    Posted 06 Aug 2018 in reply to Vessy Link to this post

    Hello Vessy,

     

    Thanks for your answer, the behavior I need is more something like CreateRowEditor, because the value column is related to the type of the item (parameter). And I need to load the editor of the row based on this type. It's like exactly what I showed with the link of kendo UI. But I need it in AJAX UI.

    Thank you !

    Regards.

    Hamza.

  6. Vessy
    Admin
    Vessy avatar
    2301 posts

    Posted 09 Aug 2018 Link to this post

    Hi Hamza,

    The sample in the linked article is using the column DataField in order to identify the column which editor to change, but you can access the DataType of the column through the same e.column object:
    protected void RadGrid1_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
    {
        GridBoundColumn column = e.Column as GridBoundColumn;
        if (column != null && e.Column.DataType.Name == "Boolean")
        {
            //one editor type
        }
        else if (column != null && e.Column.DataType.Name == "String")
        {
            //other editor type
        }
    }


    Regards,
    Vessy
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top