Is there an efficient way (ClientSide) to select an item in a WebDropDown based on the VALUE (happens to be an Integer) rather than the TEXT? The method [set_currentValue] does not do what I expected (it should be called [set_CurrentText] IMHO.)
I currently have to scan the items in the dropdown list looking for the one that has the correct value and then use its text to set the selected item, thus:
function setDROP(clientID, val) { // clientID of the WebDropDown, val = INT value var dd = $find(clientID); // get the dropdown control dd.set_selectedItemIndex(-1); // de-select all var items = dd.get_items(); // get the items[] var iCount = items.getLength(); // how many we got? for (var i = 0; i < iCount; i++) // scan the items { var itm = items.getItem(i); // get the next item if (itm.get_value() == val) // does its value match? { dd.set_currentValue(itm.get_text(), true); // Yes, set the WebDropDown by specifying the text associated with the value break; // we are done... } } }
This is VERY inefficient and requires on average a scan of half of the items in the list, yuk.
Any ideas on how best to do this? Surely there must be a better way.
Kind regards,
Paul
Hi,
Here's the forum post which has the bad news that you can't find an item by value:
https://ko.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/38528/how-can-i-programatically-csom-select-an-item-in-the-webdropdown/221251#221251
Even if there would be a built in client side function for this, it probably wouldn't help efficiency because they would most likely have to loop through all the values internally. It would be neater though.
Ed
Thanks for this:
"It would be neater though."
1) It's not just about neatness. Nearly all of the IG worked examples are unrealistic when it comes to real database use. In all my 35 years of IT work and database design I have never developed or used a system where a selection is made from a list of texts (as per the IG samples for WebDropDown). In a properly normalised database there will always be selection made by reference to a lookup table that contains a uniquely numbered list; a reference to this number being stored in the master table and refering to the appropriate entry in the lookup table. Any database designer who uses a list of real texts as per your samples should, quite frankly, be taken out and shot at dawn.
2) You are forcing your customers to bang their head against this brick wall and re-invent a kludge to work around the lack of functionality. Every developer who is dealing with properly normalised databases will encounter this issue and have to derive a solution if they are using your control.
Please put this functionality into the WebDropDown. It means that instead of the call to a custom JavaScript function the process can, in the case of my example, be encapsulated in a single line of declaration in the RowEditingClientBinding statement in a WebDataGrid. Had it been available it would have saved me many hours of frustration.
Kind regards
Paul,
I agree totally with you. Please make a note though that I DO NOT work at Infragistics and do not deserve to be shot at dawn:)
Thanks, Ed
Selecting an item by text or value on the client side (programatically via the API) is not currently supported in constant time. Only selecting by index , if you know the item index in advance, does that. This is because in the client state items are not mapped and hashed by text or by value. In order to optimize the client state / bandwidth usage, items are sent as plain arrays with well-known indices for all their properties.
So right now, even if you select an item by text, it still traverses the collection until the item is found.
Thanks,
Angel
Oops, apologies Ed,
I saw something relating to IG in the header of your reply and jumped to the wrong conclusion. You're safe, the AK47's safety catch is back on.
I do appreciate your responses.
Nonetheless, I hope IG are watching this thread - if so, any chance of a comment?