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

[Solved] Importing a selected string into Editor from a Control

1 Answer 125 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 26 Dec 2009, 08:30 PM
Hi...

-- Is there a way to import into RadEditor a user's control selection? The control selection might be from a RadListBox, RadGrid or ListView. 

-- I am needing to select and import nvarchar(max) items... normally 2 to 3 sentence blocks of text .

-- I tried using the snippet and custom toolbar dropdowns but it is tough to distinguish between the various items when the dropdown is activated.

Thoughts?

Brad

1 Answer, 1 is accepted

Sort by
0
Accepted
Dobromir
Telerik team
answered on 28 Dec 2009, 11:24 AM
Hi Brad,

If your scenario have two separate controls on the page you can create a custom tool or custom dialog to paste the selection of a specific control inside the content area. RadEditor's Client-Side API has a method pasteHtml() to insert content in the RadEditor's content area.

In addition, you should have in mind that when you set the focus outside RadEditor (for example when  clicking on RadGrid) you are loosing the selection and the text will be pasted at the start of the content using pasteHtml().

The following example demonstrates how to insert a column value from RadGrid's selected row in the RadEditor's content area:
        <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server"
            AllowPaging="True" GridLines="None" PageSize="10" Width="95%" ShowStatusBar="true">
            <PagerStyle Mode="NumericPages" />
            <MasterTableView ClientDataKeyNames="CompanyName" Width="100%" >
            </MasterTableView>
            <ClientSettings ReorderColumnsOnClient="True" AllowColumnsReorder="True" EnableRowHoverStyle="true">
                <ClientEvents OnRowSelected="RowSelected" OnRowDeselected="RowDeselected"></ClientEvents>
                <Selecting AllowRowSelect="True"></Selecting>
            </ClientSettings>
        </telerik:RadGrid>
 
        <telerik:RadEditor ID="RadEditor1" runat="server" OnClientSelectionChange="OnClientSelectionChange">
            <Tools>  
                <telerik:EditorToolGroup>  
                    <telerik:EditorTool Name="PasteFromRadGrid" Text="Paste From RadGrid" />
                </telerik:EditorToolGroup>  
            </Tools>  
        </telerik:RadEditor>
<telerik:RadScriptBlock ID="ScriptBlock" runat="server">
<script type="text/javascript">
  
    var activeRowContent = new String(); //content container
    var selectionStorage = null;//selection container
      
    //fill the content container onrowselected
    function RowSelected(sender, args) {
        activeRowContent = args.getDataKeyValue("CompanyName");
    }
    //empty the content container onrowdeselected
    function RowDeselected(sender, args) {
        activeRowContent = "";
    }
  
    function OnClientSelectionChange(editor, args) {
        selectionStorage = editor.getSelection().getRange();//save a restore point for the current position/selection in the RadEditor's content area
    }
  
    Telerik.Web.UI.Editor.CommandList["PasteFromRadGrid"] = function(commandName, editor, args) {
        editor.getSelection().selectRange(selectionStorage);
        editor.pasteHtml(activeRowContent);
    };
  
</script>  
</telerik:RadScriptBlock>        

Note that the example is missing the DataSource provider and will not work without it, so you should add it. The declaration of RadGrid is present due to the
<MasterTableView ClientDataKeyNames="CompanyName" Width="100%" >
declaration because ClientDataKeyNames property should be populated with the column(s) name in order to get their values.
Additional information regarding data extraction from RadGrid is available in the following article:
Extracting key values client-side


However, if you are trying to insert one of those controls as a custom tool in the RadEditor - information regarding this is available in the following Forum thread:
Can I add a combobox to radeditor's tools collection?

Best regards,
Dobromir
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Editor
Asked by
Brad
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Share this question
or