Simple Question can you change the selected item of all the RadComboBoxes in a RadGrid with JavaScript

1 Answer 78 Views
ComboBox Grid
Keith
Top achievements
Rank 1
Iron
Iron
Keith asked on 04 Apr 2023, 10:28 PM

Dont need to show me how. It would be appreciated, but at 1st I need to know if it is possible to on the client iterate through rows on a RadGrid and change the selected item of a RadComboBox in each row.  It isnt our ultimate goal. We want when a parent row is changed for all the comboboxes in the child to get changes to the same, but the code below is a start.

I try this and no visible change is made in the grid.

 

for (var i = 0; i < Telerik.Web.UI.RadComboBox.ComboBoxes.length; i++) {
    var combo = Telerik.Web.UI.RadComboBox.ComboBoxes[i];

     var item = combo.findItemByText(changedValue);
     if (item) {
           item.select();
                    }
                }
for (var i = 0; i < Telerik.Web.UI.RadComboBox.ComboBoxes.length; i++) {
                    var combo = Telerik.Web.UI.RadComboBox.ComboBoxes[i];

                    var item = combo.findItemByText(changedValue);
                    console.log(item);
                    if (item) {
                        item.select();
                    }
                }

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 07 Apr 2023, 02:51 PM

Hello Keith,

Yes, it is possible and the approach might be different depending on the Grid's EditMode. 

If the Grid uses any EditMode other than "Batch" and the rows are in edit mode, you can use jQuery to find the Combos in the Edit Forms, then select an item for each.

// Find all RadComboBox elements by class name and iterate through each
$('.RadGrid .rgEditForm .RadComboBox').each(function(index, element) { 
    // cast the element to Telerik.Web.UI.RadComboBox object
    var radComboBox = element.control;

    // Set the Text in case the Filtering/Load On Demand are enabled
    radComboBox.set_text("Set the Text")

    // Otherwise

    // Find the item by value and select it accordingly
    var itemToselect = radComboBox.findItemByValue("YourValue");

    if(itemToselect){
        itemToselect.set_selected(true);
    }
});

If using BacthEdit mode, that will require a different approach because of the RadGrid Batch Editing Templates and Specifics.

Instead of finding the Combos in the Grid, you would rather need to set the value to the Grid's Cell. Here is one Knowledge Base article on that topic: Cascading ComboBoxes with BatchEditing and Master/Detail Hierarchy

Of course, you can access the Controls too if you wanted. We have an article describing the process, see Working With Templates

Here are a few other examples that may give you a good idea of how to work with Batch Editing on the Client Side:

I hope this will prove helpful.

Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox Grid
Asked by
Keith
Top achievements
Rank 1
Iron
Iron
Answers by
Attila Antal
Telerik team
Share this question
or