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

[Solved] select table element in runtime

1 Answer 165 Views
Editor
This is a migrated thread and some comments may be shown as answers.
gerco Koks
Top achievements
Rank 1
gerco Koks asked on 18 Feb 2010, 03:30 PM
Hi,

I've created a custom toolbar button wich paste a vertical buttonlist in the editor. the buttonlist in nested in a 3x3 table. After pasting it i want to select the table by using the setActive() method. This is not working. Is it possible to get it work.
editor.pasteHtml(verticalRadioBuutonListAsHtml, commandName);  
var insertedElem = editor.get_document().getElementById(id);  
if (insertedElem) {  
        if (insertedElem.setActive) {  
            insertedElem.setActive();  
        }  
    } 
Other elements do work this way.

Gerco

1 Answer, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 23 Feb 2010, 08:50 AM
Hi Gerco,

setActive() is a client-side method which sets the focus on the RadEditor's content area, not on an element inside. In order to select element programmatically you need to use RadEditor's selection client-side methods getSelection().getRange() and getSelection().selectRange(range). You can find more information on the subject in the following help articles:
http://www.telerik.com/help/aspnet-ajax/editor_getselection.html
http://www.telerik.com/help/aspnet-ajax/getrange.html

The following example demonstrates how to select the first cell of a initially inserted table OnClientLoad of the editor.
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="OnClientLoad">
    <Content>
        <table id="myTable">
            <tr>
                <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
            </tr>
            <tr>
                <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
            </tr>
            <tr>
                <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
            </tr>
        </table>
    </Content>
</telerik:RadEditor>
 
<script type="text/javascript">
 
    function OnClientLoad(editor, args)
    {
        var oDoc = editor.get_document();
        setTimeout(function()
        {
            var elemToSelect = oDoc.getElementById("myTable");
 
            editor.getSelection().selectElement(elemToSelect.getElementsByTagName("TD")[0]);
            editor.raiseEvent("selectionChange");
 
            if ($telerik.isIE) editor.setActive();
            else editor.setFocus();
        }, 100);
    }
 
</script>

I hope this helps.

All the best,
Dobromir
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
Editor
Asked by
gerco Koks
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or