custom button extended from editor button?
custom button extended from editor button?
in Editor
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> ' +
'New',
sToolTip : 'New'
},
{
sExtends : "editor_edit",
editor : myEditor,
sButtonClass: 'btn-success',
sButtonText : '<i class="fa fa-pencil-square-o"></i> ' +
'Edit',
sToolTip : 'Edit'
},
{
sExtends : "editor_remove",
editor : myEditor,
sButtonClass: 'btn-danger',
sButtonText : '<i class="fa fa-trash-o"></i> ' +
'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?
This discussion has been closed.
Answers
Hi,
When you make use of the button in the DataTables / TableTools initialisation, do you pass in the Editor instance as the
editorproperty? It looks like probably not, as the error suggests that the default value ofnullis being used.Allan
Yes! If I define an editor button I pass an
Editorinstance as theeditorproperty and it works well but in this case I do not want to define an editor button! please see this again:but it behaviours as an editor button!
Ah - got it.
Use:
to create your button - i.e. extend an empty object, rather than modifying the existing select_single button.
Allan
That's not solution!
I want to use
http://datatables.net/extensions/tabletools/button_optionsto modify button and in this page, undersExtends, you said that I can extend a predefined button and make my own button, is it wrong?That is correct. Before it was modifying the
select_singlebutton 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
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 :-)
http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read