What is the recommended way to set the selected value of a dropdownprovider(WebDropDown) on the client side via javascript?
I have a WebHeirarchicalDataGrid with a column that has a DropDownProvider as the editor. On the client side, when I add a new row I want to be able to set the selected value for this dropdown. With the old UltraWebGrid you could just set the value and things just worked. With the new WHDG, setting the value also sets the display text for the dropdown unless you specify the text to display.
I am looking for something like setSelectedItem() or setSelectedIndex(). I saw one post which suggested setting the innerhtml of the element and this would auto select the appropriate item, this seems like a hack...
Hi elPato79,
You could use set_selectedItemIndex() and set_currentValue() client-side methods of WebDropDown. Here is another related thread - http://ko.infragistics.com/community/forums/p/72506/367778.aspx.
Let me know if this helps.
Hi Nikolay,
Thank you for the prompt response. Your suggestion for the WebDropDown works well when using it directly. However in this case the WebDropDown is the editor associated to the DropDownProvider of my WebHeirarchicalDataGrid column. So in my case I have a handle to a specific cell, when inspecting the cell on the client side it does not expose the two methods you suggested which makes sense because I believe the WebDropDown is a seperate element that is overlayed and shown when the cell is active.
I would prefer not to resort to getting a handle to the WebDropDown via $find{[ID]}, seems like there should be some better programatic way to access the WebDropDown or a utliity method on the cell to set the selected value for the cell's editorprovider. If I drill down through the grid object I think I have access to the editors collection and from there can iterate across looking for my specific cell's editorprovider, and then pull the editor from that at which point I should have a handle to the WebDropDown object where I can call the two methods you suggested. This seems rather inefficient, can you think of a better approach?
Hello elPato79,
Could you please clarify your scenario? On which event are you trying to set the value of the editor provider and is this provider associated with CellEditing or RowAdding column settings?
My scenario is:
-Click a button which calls js function to Add a new row client side
-Within the same function after row is added, I want to set the selected value for a specified cell that has a dropdownprovider associated to it.
-The provider is associated with CellEditing column setting
Currently if I set the text and the value of the cell, things appear to get wired up correctly, but this is not efficient because then I need to know both the value and text that I want to set the cell too. For a single page with a grid, this isnt that big of a deal, but in my case I am creating a user control that is going to be used on hundreds of pages and I would prefer not to have to maintain both text and value for each dropdown I want to default. Again with the old UltraWebGrid I could just set the value and be done with it, I am just looking for a comparable approach.
Thanks for your help.
You could only set the value of the cell, the text will be automatically set equal to the value.
Thanks for the reply Nikolay,
Your suggestion works well when the text and value are the same, in my scenario text(display) value and actual value are different.
I appreciate your help with this, I am just going to write this off as a minor nuance between UltraWebGrid and WebHeirarchicalDataGrid. I'll adjust my user control to manage both default Text and Value and then set both on row added event.
Thank you for the follow up. If you have any other questions or concerns please do not hesitate to ask.