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

How to create custom DeleteTable toolbar button

7 Answers 121 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 03 Jan 2017, 04:28 PM
Hi,

I want to create a custom toolbar button to delete table I see there is a command DeleteTable, does this support undo/redo??

Should I be able to fire this command simply using??
editor.fire("DeleteTable");

7 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 04 Jan 2017, 01:08 PM
Hi,

You can delete a table inside the content area using this line of code:

editor.fire("DeleteTable", true);

Regards,
Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tomas
Top achievements
Rank 1
answered on 05 Jan 2017, 05:15 PM
This removes the table yes, but undo does not work thought.

As this is a generic command I would expect undo to restore the table, but it undoes the previous action.

0
Rumen
Telerik team
answered on 06 Jan 2017, 12:03 PM

Hi Brian,

There is a private _deleteTable(tableElement) method, which you can use to delete a selected table and add this operation to the Undo/Redo list:

EditorCommandList["TableDelete"] = function (commandName, editor, args) {
    var selectedElement = editor.getSelectedElement();
             
    while (selectedElement.tagName.toLowerCase() != "table") {
        selectedElement = selectedElement.parentNode;
    }
    if (selectedElement.tagName.toLowerCase() == "table") {
        editor._deleteTable(selectedElement);
    }
};

Best regards,

Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tomas
Top achievements
Rank 1
answered on 06 Jan 2017, 05:33 PM

Hi Rumen,

Can you give me an example with it adding the operation to the undo/redo list as well please?

Thanks

0
Accepted
Rumen
Telerik team
answered on 09 Jan 2017, 09:09 AM

Hi Brian,

The execution of the _deleteTable() method automatically adds an entry in the undo list as you can see in the following video: http://screencast.com/t/HGK9o9E7orDW.

Best regards,

Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Sean
Top achievements
Rank 1
answered on 01 Nov 2018, 04:31 PM

Hello,

I have a similar question/problem. For some specific reason, we want to modify existing "DeleteTable" Command to preserve State before and after delete. We are doing something like following:

Telerik.Web.UI.Editor.CommandList["DeleteTable"] = function(commandName, editor, args){

     //some stuff goes here...

    var cmd = new Telerik.Web.UI.Editor.DeleteTable("Delete Table", editor.get_contentWindow(), editor, customManager);

    preserveStateBefore here

     editor.executeCommand(cmd,false,true);

     preserveStateAfter here

}

Just like Modules as shown on this link:

https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/functionality/modules/custom-modules 

we setup Editor.DeleteTable = function(){ ... }, Editor.DeleteTable.prototype ={ close:function(){ ...} ...}

then when  i say Telerik.Web.UI.Editor.DeleteTable.registerClass('Telerik.Web.UI.Editor.DeleteTable',Telerik.Web.UI.Editor.CommandBase);   

last line throws javascript exception that something is already registered.

"JavaScript runtime error: Sys.InvalidOperationException: Type Telerik.Web.UI.Editor.DeleteTable has already been registered. The type may be defined multiple times or the script file that defines it may have already been loaded." 

Can you help me with how to do this properly? i thought it might act as pointer and i wont have to update it but that is not the case. Any help will be appreciated.

Thank you,

Sean

0
Rumen
Telerik team
answered on 06 Nov 2018, 03:24 PM
Hello,

You can override the built-in DeleteTable function as shown below:

<script>
    Telerik.Web.UI.Editor.CommandList.DeleteTable =  function(commandName, editor, args)
    {
        console.log("test");
        var oElem = args.value;
        if (!oElem)
        {
            oElem = editor.getSelectedElement();
        }
 
        if (oElem && "TABLE" != oElem.tagName) //Can be a TD - so obtain the table from the TD.
        {
            oElem = Telerik.Web.UI.Editor.Utils.getElementParentByTag(oElem, "TABLE");
        }
 
        if (oElem)
        {
            //#track changes
            if (!editor.get_enableTrackChanges() || editor.get_enableTrackChangesOverride())
            {
                var range = editor.getDomRange();
                range.setStartBefore(oElem);
                range.collapse(true);
                $telerik.$(oElem).remove();
                range.select();
            }
            else
            {
                var selection = editor.getSelection();
                Telerik.Web.UI.Editor.TrackChangesUtils.wrapElementInTrackChangeDelete(selection.getParentElement(), editor.get_author());
            }
            //#end track changes
        }
    }
</script>
<telerik:RadEditor ID="RadEditor1" runat="server"></telerik:RadEditor>

This will allow you to execute your own code at the desired location.


Regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Editor
Asked by
Tomas
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Tomas
Top achievements
Rank 1
Sean
Top achievements
Rank 1
Share this question
or