Batch Editing Extensions - Related RadComboBoxes and Batch Validation

Thread is closed for posting
13 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 15 Feb 2015 Link to this post

    Requirements

    Telerik Product and Version

    Q3 2014 (2014.3 1209) or above

    Supported Browsers and Platforms

    All supported browsers 

    Components/Widgets used (JS frameworks, etc.)

    jQuery
    PROJECT DESCRIPTION

    This Code Library provides an extension for the RadGrid Batch Editing functionality, which allows you to implement related RadComboBoxes functionality between column and to set Batch Validation. Each of the functionalities is easily integrated with RadGrid in Batch edit mode through separate managers.

    Batch Extensions


    Related RadComboBoxesManager 


    Due to the way that Batch Editing is implemented, having related drop down controls with enabled LoadOnDemand functionality is almost impossible to be achieved or will require a ton of custom JavaScript. In the attached BatchExtensions object in this Code Library, the RelatedComboBoxesManager simulates such functionality by displaying a RadToolTip with RadComboBox control over the currently edited cell. The only thing that you need to do to enable the related RadComboBox functionality is to set the grid object, specify the RadToolTip containing the RadComboBox control, set the columns relationships and handle the server-side OnItemsRequested event of the RadComboBox to provided the data. Everything else will be handled by the manager.


    Integration

    Before you start the integration of the RelatedComboBoxesManager, you need to include the batchManagerExtensions.js and batchManagerExtensions.css files in your project. After including those files, you will have to follow the steps below:

    1) Copy and paste the following RadToolTip within the same container as the RadGrid (especially when you are using RadAjax):
    <telerik:RadToolTip runat="server" ID="RelatedComboBoxesToolTip" OffsetY="0" RenderInPageRoot="false"
        HideEvent="FromCode" AutoCloseDelay="0" RelativeTo="Element" CssClass="RelatedCombosToolTip"
        ShowEvent="FromCode" Position="Center" Skin="Default">
        <telerik:RadComboBox runat="server" Width="100%" EnableLoadOnDemand="true" OnItemsRequested="RadComboBox1_ItemsRequested">
        </telerik:RadComboBox>
        <telerik:RadToolTip runat="server" Skin="Metro" OffsetY="0" EnableShadow="false" ShowEvent="FromCode" Position="TopCenter"></telerik:RadToolTip>
    </telerik:RadToolTip>


     2) Add the server-side handler for the OnItemsRequested event of the RadComboBox. Within that event you will have access to the column name and the related cell value, which should be enough for getting the items that should be displayed in a particular cell:
    protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        RadComboBox comboBox = sender as RadComboBox;
        string columnName = e.Context["ColumnName"].ToString();
        string relatedValue = e.Context["RelatedValue"] != null ? e.Context["RelatedValue"].ToString() : "";
         
        // Get the data and create Items for the RadComboBox
        ...


     3) The next step is to attach event handler for the client-side OnGridCreated event, where we will initialize the RelatedComboBoxesManager:
    function gridCreated(sender, args) {
        var relatedComboBoxesManager = new BatchExtensions.RelatedComboBoxesManager().init({
            grid: sender,
            toolTipID: "<%=RelatedComboBoxesToolTip.ClientID%>",
            relations: [
                {
                    columnName: "Continent"
                },
                {
                    columnName: "Country",
                    relatedTo: "Continent"
                },
                {
                    columnName: "City",
                    relatedTo: "Country"
                }
            ]
        });
    }


    Important Note

    The RelatedComboBoxesManagers will work with bound columns and GridTemplateColumn with the following ItemTemplate:
    <ItemTemplate>
        <%# Eval("City") %>
    </ItemTemplate>

    You should also have in mind that RelatedComboBoxesManager will work only with Cell edit mode.



    Batch Validation - ValidationManager

    Although that Batch Editing supports standard Validatiors, they do not provide a great user experience in the context of Batch Editing, because the user will not be able to leave the cell until the values is valid. Furthermore, the error messages will be displayed besides the editor, which could lead to distorted layout of the grid. The ValidationManager from the BatchExtensions is created to handle the validation with Batch Editing in very user-friendly manner, where the error messages is displayed in the cells (in normal mode) and the user will still be able to perform other operations, even if there is failed validation. 

    Integration

    Before you start the integration of the ValidationManager, you need to include the batchManagerExtensions.js and batchManagerExtensions.css files in your project. After including those files, you will have to follow the steps below:

    1) Attach event handler for the client-side OnGridCreated event of your RadGrid:
    <ClientSettings>
        <ClientEvents OnGridCreated="gridCreated" />
    </ClientSettings>

    2) Within the handler for the OnGridCreated event, initialize a new ValidationManager for the grid and set your validators for the column that you need to validate:
    function gridCreated(sender, args) {
        grid1Validator = new BatchExtensions.ValidationManager().init({
            grid: sender,
            validators: [
                {
                    columnName: "Continent",
                    errorMessage: "- Required -"
                },
                {
                    columnName: "Country",
                    errorMessage: "- Required -"
                },
                {
                    columnName: "City",
                    errorMessage: "- Required -"
                },
                {
                    columnName: "Numeric",
                    errorMessage: "",
                    toolTipMessage: "Select a positive number",
                    validationFunction: function (value) {
                        return value >= 0;
                    }
                },
                {
                    columnName: "Date",
                    errorMessage: "Select a future date",
                    validationFunction: function (value) {
                        return !(Date.parseInvariant(value) < new Date().setHours(0, 0, 0, 0));
                    }
                }
            ]
        });
    }

    As you can notice, each validator accepts the columnName (required) and the following optional properties:
    • errorMessage - The message that will be displayed within the cell on failed validation;
    • toolTipMessage - The message that will be displayed on hovering over a cell with failed validation;
    • validationFunction - Custom validation function that has the current value as an argument and defines on what conditions the value is valid.


    ValidationManager Methods 

    • add_validator({...}) - adds new validator to the ValidationManager:
    grid1Validator.add_validator(
            {
                columnName: "Continent",
                errorMessage: "- Required -"
            }
    );

    • add_elementToDisable(element) - adds an element that will be disabled when RadGrid is invalid and has cells with failed validation. By default, the Save Changes button of RadGrid is included in this collection of elements and the user will not be able to save the changes, unless all cells are valid:
    grid1Validator.add_elementToDisable(document.getElementById("<%= Button1.ClientID %>"));

    • isValid() - this method will return true if all the cells in the grid are valid (this method could be useful within the client-side OnUserAction event of the grid, where you can prevent paging, sorting, filtering, etc., if there is failed validation): 
    function userAction(sender, args) {
        if (!grid1Validator.isValid()) {
            args.set_cancel(true);
        }
    }



  2. A19DCED0-98E5-45E2-B42F-F643C651E101
    A19DCED0-98E5-45E2-B42F-F643C651E101 avatar
    17 posts
    Member since:
    Jun 2012

    Posted 28 Apr 2015 in reply to 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD Link to this post

    How can i include the libraries into the project?
  3. 5AB28265-E69E-4E21-A72B-1CCE9F27420A
    5AB28265-E69E-4E21-A72B-1CCE9F27420A avatar
    2466 posts
    Member since:
    Apr 2022

    Posted 30 Apr 2015 Link to this post

    Hi,

    As mentioned in the description (and as could be seen in the attached page), you need to include the batchManagerExtensions.js and batchManagerExtensions.css files in your project:
        <link href="batchManagerExtensions.css" rel="stylesheet" />
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                    <asp:ScriptReference Path="batchManagerExtentions.js" />
                </Scripts>
            </telerik:RadScriptManager>


    Regards,
    Konstantin Dikov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  4. 88D9665B-E8BA-4D93-BCFE-F948426C433C
    88D9665B-E8BA-4D93-BCFE-F948426C433C avatar
    53 posts
    Member since:
    Oct 2007

    Posted 14 Apr 2016 in reply to 5AB28265-E69E-4E21-A72B-1CCE9F27420A Link to this post

    I'm using this sample as a starting for a screen behaviour we want.

    I "copied" the sample to study how it works and, then, make the corrections we need.

    For my surprise, when I change the value of a combo and then I click the "tab" to go to next field, the next "editable" field will be the navigation bar, not the next combo.

    Is there any way to avoid this?

  5. 5AB28265-E69E-4E21-A72B-1CCE9F27420A
    5AB28265-E69E-4E21-A72B-1CCE9F27420A avatar
    2466 posts
    Member since:
    Apr 2022

    Posted 18 Jul 2016 Link to this post

    Hello,

    The attached files are updated and the extension for the related RadComboBoxes now handles correctly the TAB key.


    Regards,
    Konstantin Dikov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. D6B94351-FD62-4747-B2D4-20370FF57364
    D6B94351-FD62-4747-B2D4-20370FF57364 avatar
    10 posts
    Member since:
    Apr 2015

    Posted 01 Feb 2017 in reply to 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD Link to this post

    This solution has a fault.  In the "public static List<DemoItem> GetX(string filterValue)" functions, a Where clause is being used and then the first item returned is assumed correct.  What if more than one item was returned in the Where clause and the second item was the valid one?
  7. D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428
    D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428 avatar
    12 posts
    Member since:
    Feb 2016

    Posted 15 Feb 2017 Link to this post

    this was an excellent add on.   However, I am a bit confused with the combo manager and using the item template.    Let's say I have a bound column, which saves an ID to a table.   The UI must show the associated text value, so we would have a list  (1, "Blue Plan") bound to the dropdown.   Now, the template column is set to show the Plan description, but the database saves PlanID. 

    When I select an entry in the dropdown, the cell text gets set correctly, but when saved to the database, the ID is null.  Am I missing something?

     

  8. 29549EA2-3D93-451B-8902-799909B69471
    29549EA2-3D93-451B-8902-799909B69471 avatar
    1 posts
    Member since:
    Jul 2015

    Posted 06 Feb 2018 Link to this post

    Hi,

    I am using the extensions. However , I would like to do some validations and save the radgrid on an external button click. how do I do that.  Also, on posback, the radgrid is loosing all the changes.

    Please help..

  9. 3C63E930-39AD-43DE-B5C0-77F76A8C59EA
    3C63E930-39AD-43DE-B5C0-77F76A8C59EA avatar
    3 posts
    Member since:
    May 2018

    Posted 03 May 2018 in reply to 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD Link to this post

    In RadComboBox1_ItemsRequested, relatedValue  has the selected item text, I want to pass the selected Item value. How to pass the Continent Id to  RadComboBox1_ItemsRequested instead of Continent  text
  10. 5CFAD4EA-70F4-4DD1-8E0A-4DEB4B54BB63
    5CFAD4EA-70F4-4DD1-8E0A-4DEB4B54BB63 avatar
    5 posts
    Member since:
    May 2017

    Posted 10 Apr 2019 Link to this post

    Is there a simple way to add more than 1 related value?
  11. D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428
    D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428 avatar
    12 posts
    Member since:
    Feb 2016

    Posted 10 Apr 2019 in reply to 5CFAD4EA-70F4-4DD1-8E0A-4DEB4B54BB63 Link to this post

    I don't believe so.  I had the same requirement (a parent column passes its value to 2 separate columns).   I had to redesign the classes to do it, using a "parent column"  relationship.  That's the opposite to how its done here.
  12. 5CFAD4EA-70F4-4DD1-8E0A-4DEB4B54BB63
    5CFAD4EA-70F4-4DD1-8E0A-4DEB4B54BB63 avatar
    5 posts
    Member since:
    May 2017

    Posted 11 Apr 2019 in reply to D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428 Link to this post

    Thanks Bryan, I had a parent column and this solve my problem.

    But now I have a new question. When I select an item from combobox system save value of DataTextField on grid and not value of DataValueField and save method goes on error.

     

    Here is source code of combobox definition

     comboBox.DataTextField = "ReasonDesc";
     comboBox.DataValueField = "ReasonCode";
     comboBox.DataBind();

  13. D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428
    D0E6F6D6-9A8D-4B31-8BB9-6456DD90C428 avatar
    12 posts
    Member since:
    Feb 2016

    Posted 11 Apr 2019 in reply to 5CFAD4EA-70F4-4DD1-8E0A-4DEB4B54BB63 Link to this post

    I also had that same requirement.

    However, the javascript also doesn't allow for a key / value pair (value would be the text). It only allows for the text.  Again, it would have to be redesigned to accommodate that.  I did not have the skills to do that, so can't really help there. 

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.