custom button extended from editor button?

custom button extended from editor button?

ansarigmbhansarigmbh Posts: 24Questions: 7Answers: 0

Hi

I added a custom button to my table with bottom code:

    aButtons: [
    {
    sExtends : "editor_create",
    editor : myEditor,
    sButtonClass: 'btn-primary',
    sButtonText : '<i class="fa fa-plus"></i>&nbsp;&nbsp;' +
    'New',
    sToolTip : 'New'
    },
    {
    sExtends : "editor_edit",
    editor : myEditor,
    sButtonClass: 'btn-success',
    sButtonText : '<i class="fa fa-pencil-square-o"></i>&nbsp;&nbsp;' +
    'Edit',
    sToolTip : 'Edit'
    },
    {
    sExtends : "editor_remove",
    editor : myEditor,
    sButtonClass: 'btn-danger',
    sButtonText : '<i class="fa fa-trash-o"></i>&nbsp;&nbsp;' +
    'Delete',
    sToolTip : 'Delete'
    },
    {
    sExtends : "select_single",
    fnInit : function (nButton, oConfig)
    {
    $(nButton).addClass(this.classes.buttons.disabled);

    },
    fnSelect : function(nButton, oConfig)
    {
    if(this.fnGetSelected().length == 1)
    {
    $(nButton).removeClass(this.classes.buttons.disabled);
    }
    else
    {
    $(nButton).addClass(this.classes.buttons.disabled);
    }
    },
    sButtonClass: 'btn-info',
    sButtonText : 'myButton',
    sToolTip : 'myButton'
    },
    ],

But when I clicked on my custom button I got an error:

TypeError: editor is null
var i18nEdit = editor.i18n.edit;

that comes from here (line 15):

    ttButtons.editor_edit = $.extend( true, ttButtons.select_single, {
            "sButtonText": null,
            "editor":      null,
            "formTitle":   null,
            "formButtons": [
                { "label": null, "fn": function (e) { this.submit(); } }
            ],
            "fnClick": function( button, config ) {
                var selected = this.fnGetSelectedIndexes();
                if ( selected.length !== 1 ) {
                    return;
                }

                var editor = config.editor;
                var i18nEdit = editor.i18n.edit;
                var buttons = config.formButtons;

                if ( ! buttons[0].label ) {
                    buttons[0].label = i18nEdit.submit;
                }

                editor
                    .title( i18nEdit.title )
                    .buttons( buttons )
                    .edit( selected[0] );
            }
        } );

why when I clicked on my custom button this function called?

Answers

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Hi,

    When you make use of the button in the DataTables / TableTools initialisation, do you pass in the Editor instance as the editor property? It looks like probably not, as the error suggests that the default value of null is being used.

    Allan

  • ansarigmbhansarigmbh Posts: 24Questions: 7Answers: 0

    Yes! If I define an editor button I pass an Editor instance as the editor property and it works well but in this case I do not want to define an editor button! please see this again:

        {
        sExtends : "select_single",
        fnInit : function (nButton, oConfig)
        {
        $(nButton).addClass(this.classes.buttons.disabled);
    
        },
        fnSelect : function(nButton, oConfig)
        {
        if(this.fnGetSelected().length == 1)
        {
        $(nButton).removeClass(this.classes.buttons.disabled);
        }
        else
        {
        $(nButton).addClass(this.classes.buttons.disabled);
        }
        },
        sButtonClass: 'btn-info',
        sButtonText : 'myButton',
        sToolTip : 'myButton'
        }, 
    

    but it behaviours as an editor button!

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Ah - got it.

    Use:

    $.extend( true, {}, ttButtons.select_single, {
    

    to create your button - i.e. extend an empty object, rather than modifying the existing select_single button.

    Allan

  • ansarigmbhansarigmbh Posts: 24Questions: 7Answers: 0

    That's not solution!

    I want to use http://datatables.net/extensions/tabletools/button_options to modify button and in this page, under sExtends, you said that I can extend a predefined button and make my own button, is it wrong?

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    That is correct. Before it was modifying the select_single button definition. With my change above it create and entirely new button definition.

    If that isn't working, please link me to a test page showing the issue so I can debug it.

    Allan

  • ansarigmbhansarigmbh Posts: 24Questions: 7Answers: 0

    finally I've overwritten fnClick() function and now everything is well. But I'm sure TableTools or Editor have a bug in button definition (as I talked before).

    and excuse me, I do not know how I can make an online test page!

    Thanks anyway :-)

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394
This discussion has been closed.