Cancel button
Cancel button
nskwortsow
Posts: 120Questions: 0Answers: 0
Hi,
When adding a new record, I would like there to be a CANCEL button as well inside the modal (not only a "Save" button).
How & where do I add this? The code below on fnInitComplete didn't do anything.
editor.buttons( [
{
"label": "Cancel",
"className":"btn btn-link",
"fn": function () {
editor.close();
}
}
When adding a new record, I would like there to be a CANCEL button as well inside the modal (not only a "Save" button).
How & where do I add this? The code below on fnInitComplete didn't do anything.
editor.buttons( [
{
"label": "Cancel",
"className":"btn btn-link",
"fn": function () {
editor.close();
}
}
This discussion has been closed.
Replies
Are your add, edit and delete buttons the default TableTools buttons? If so, you need to add the cancel button. You could do something like:
[code]
TableTools.BUTTONS.editor_edit.formButtons.push( ... button def ... );
[/code]
Allan
Where should I insert the snippet?
TableTools.BUTTONS.editor_edit.formButtons.push(xxx)
###
And how should I format my button def? Like
###
editor.buttons( [
{
"label": "Cancel",
"className":"btn btn-link",
"fn": function () {
editor.close();
}
}
> And how should I format my button def?
Using exactly the same format as the `buttons` method as you suggest. Although obviously use `this` rather than the `editor` variable, since `editor` won't have been defined by that point.
Allan
Your documentation:
http://editor.datatables.net/api/
My implementation (after
[code]editor = new $.fn.dataTable.Editor(
{ /.../ }[/code]:
[code]
editor.buttons(
{
"label": "Cancel",
"className":"btn btn-link",
"fn": function () {
this.close();
}
});
[/code]
Following the example in your documentation.
But: no cancel button is shown...
Please advise.
N
Which code do I use to show a custom cancel button inside my editor?
[code]
TableTools.BUTTONS.editor_create.formButtons.unshift( {
... button def ...
} );
TableTools.BUTTONS.editor_edit.formButtons.unshift( {
... button def ...
} );
[/code]
Allan
I've added this code *before* instantiating the editor. No cancel button is added?
[code]
TableTools.BUTTONS.editor_edit.formButtons.push(
{
"label": "Cancel",
"className":"btn btn-link",
"fn": function () {
this.close();
}
});
[/code]
Isn't TableTools the class for showing buttons above datatables?
> Note: the cancel button is to be shown in the footer of the modal when creating a new record.
You do realising you are adding the cancel button to the `editor_edit` button set (i.e. the edit buttons) and not the create but ( `editor_create` )?
Allan
Problem resolved, thanks Allan.
Note that the label is "save" but the action is correct (it closes the editor).
Is there a way to prevent this?
[code]
TableTools.BUTTONS.editor_create.formButtons.unshift(
{
"label": "Cancel",
"className":"btn btn-link",
"fn": function () {
this.close();
}
});
[/code]
[code]
ttButtons['editor_'+val].formButtons[0].label = i18n[val].submit;
[/code]
Because the button is being `unshift` -ed into place, the `[0]` index now refers to the 'wrong' button for the internalisation options. I think the Editor core will need to have a private flag on the original button to stop that.
Until then, can you `push` it on and use CSS to change the order of the elements? Float left rather than right or vice versa?
Allan