This is a migrated thread and some comments may be shown as answers.

radcombobox in radgrid's template

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 12 Apr 2010, 02:03 PM
Hi all!
1. I have radgrid, couple template columns contaning text box and combobox, and select column.
2. when I select any item from combobox I need to know the grid's row (ItemIndex) where I change the item in teh combobox.
3. All these operations I need to perform in client-side, with the client API.

Thank you very much in advance.

Boris

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 15 Apr 2010, 09:54 AM
Hi Boris,

Sample page demonstrating the scenario is attached. Note that a better practice is getting a data key value for an item instead of a row index, because row indexes can get messed up, for example with sorting.

Kind regards,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Boris
Top achievements
Rank 1
answered on 15 Apr 2010, 12:29 PM
Hi Veli,
Thank you very much!!
It is perfect!
Once again, thank you.

Now there is one question btw:
When I work with the client-side rad combobox (data bounded from server side) sometimes I need to change the selected item to another one (in client-side). I was forced to use both methods - set_value(a) and set_text(a). In code behind (C#) I can use properties - SelectedValue = ... or SelectedIndex = ... . Maybe I misunderstand?

Thank you very much in advance.

Boris



0
Veli
Telerik team
answered on 16 Apr 2010, 12:36 PM
Hi Boris,

Here is the code you would be using:

function comboIndexChanged(sender, args)
{
    var item = findParentGridItem(sender.get_element());
                     
    $get("result", item.get_element()).innerHTML = String.format("Combo value: {0}, Item index: {1}, ID: {2}",
                                             args.get_item().get_value(),
                                             item.get_element().sectionRowIndex,
                                             item.getDataKeyValue("ID"));
}
 
function selectComboItem(sender, args)
{
    var item = findParentGridItem(sender);
    var combo = $telerik.findControl(item.get_element(), "RadComboBox1");
    var id = item.getDataKeyValue("ID");
 
    var comboItem = combo.findItemByValue(id);
    if (comboItem)
    {
        comboItem.select();
    }
}
 
function findParentGridItem(element)
{
    var rowEl = Telerik.Web.UI.Grid.GetFirstParentByTagName(element, "tr");
    var grid = $find('<%= RadGrid1.ClientID %>');
    var items = grid.get_masterTableView().get_dataItems();
     
    return items[rowEl.sectionRowIndex];
}

selectComboItem() is a function run after the click event of a link button in a grid column:

<telerik:GridTemplateColumn>
    <HeaderStyle Width="120px" />
    <ItemTemplate>
        <a href="#" onclick="selectComboItem(this, event); return false;">match combo item</a>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Modified test page is attached. For more info on the RadComboBox client object, refer to the following help article.

All the best,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Veli
Telerik team
Boris
Top achievements
Rank 1
Share this question
or