sButtonText not working when extending editor_create

sButtonText not working when extending editor_create

jammybjammyb Posts: 12Questions: 3Answers: 0
edited March 2014 in TableTools
I have the following code, however this results in a Create form with two buttons displaying the text "Create". How do I change this text? Is this a bug?

[code]
"oTableTools": {
"sRowSelect": "single",
"aButtons": [
{
"sExtends": "editor_create",
"sButtonClass": "editor_create",
"editor": editorGridMaterialsDT,
"formButtons": [
{
"label": "Create",
"sButtonText": "Create & Add Another",
"className": "create_next",
"fn": function (e) {
this.submit( function () {
$('a.editor_create').click();
}, null, null, false );
}
},
{
"label": "Create",
"className": "create",
"fn": function (e) {
this.submit();
}
}
]
},
[/code]

Thanks in advance for your help.

Replies

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    The `sButtonText` option is an option for the TableTools buttons - not the Editor buttons. For that you want to use the `label` which you currently have set to 'Create' for both Editor form buttons, which is why they are both showing up as 'Create'!

    Allan
  • jammybjammyb Posts: 12Questions: 3Answers: 0
    Ah dammit. I had changed the label value but then changed it back in my attempts to get it working. Here's my correct code:

    [code]
    "oTableTools": {
    "sRowSelect": "single",
    "aButtons": [
    {
    "sExtends": "editor_create",
    "sButtonClass": "editor_create",
    "editor": editorGridMaterialsDT,
    "formButtons": [
    {
    "label": "Create & Add Another",
    "sButtonText": "Create & Add Another",
    "className": "create_next",
    "fn": function (e) {
    this.submit( function () {
    $('a.editor_create').click();
    }, null, null, false );
    }
    },
    {
    "label": "Create",
    "className": "create",
    "fn": function (e) {
    this.submit();
    }
    }
    ]
    },
    [/code]

    Still both buttons display 'Create'.
  • jammybjammyb Posts: 12Questions: 3Answers: 0
    Playing around a bit more I've discovered that the label value is only applied with the second button button in the array.
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    I think this is a bug in Editor 1.2. You can see the same thing in my next / previous button example unfortunately: https://editor.datatables.net/release/DataTables/extras/Editor/examples/back-next.html .

    I can send over a beta version of Editor 1.3 if you like - that resolves this issue? I couldn't see a purchased or trial license for your account - are you using Editor downloaded from a different account? Could you let me know which one, if so, so I can update my records and ensure you get the correct level of support!

    Allan
  • jammybjammyb Posts: 12Questions: 3Answers: 0
    Yes, for some reason when I tried to sign up with my normal email address the form stated it was unavailable? I don't think I've signed up before...

    The address I purchased the Editor with was james at code 99.

    Thanks.
  • jammybjammyb Posts: 12Questions: 3Answers: 0
    edited March 2014
    Also, I think I've found a typo with one of the examples: https://editor.datatables.net/release/DataTables/extras/Editor/examples/localstorage.html

    I believe the line 87 should be changed from
    [code]if ( store[i].DT_RowId === 'row_'+i ) {[/code]
    to
    [code]if ( store[i].DT_RowId === id ) {[/code]
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Heh - thanks for the clarification. Should I transfer the license over to this account?

    Would you like a beta copy of 1.3 which resolves this issue?

    Regarding the localStorage example - I think it is actually correct at the moment because the id is stored with the `row_` prefix: `"DT_RowId": 'row_'+store.length, ` . Unless I'm missing something?

    Thanks,
    Allan
  • jammybjammyb Posts: 12Questions: 3Answers: 0
    If you could change the email address of this account to match the email address that I used to purchase the editor with, that would be great.

    Please do send me the beta copy of 1.3.

    The problem is, it always returns i=0. Step through it for an id='row_1' at index 1. First time through the loop, i=0, so the if statement is if(store[0].DT_RowId === 'row_0'). In my case, this is true, however it's not the index of the id I'm after.
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    E-mail addresses for your two accounts reversed :-).

    LocalStorage - yup I see the point. It should be checking `'row_'+id` - oops! Thanks for pointing that out. Will be fixed in the 1.3 (although not the beta package I've just sent over...).

    Allan
  • jammybjammyb Posts: 12Questions: 3Answers: 0
    Thanks for sorting out the email addresses and sending through the 1.3 package.

    With regards to the LocalStorage example, id gets sent through as 'row_1', so it just needs to be id, not 'row_'+id. (I made the same mistake initially) :)
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    oh my. Doh! Thanks! :-) I'm going to run through that code properly with debug statements and make sure its doing what it should be...

    Allan
  • fabianrottfabianrott Posts: 30Questions: 1Answers: 0
    Hi,
    i need the same 'create & add another' functionality. Of course I tried to get the code above to do the work. To work around the bug mentioned above I relocated the buttons:
    [code]
    editor = new $.fn.dataTable.Editor({
    "ajaxUrl": "ajax_dummy",
    "domTable": "#table-view",
    "idSrc": "0",
    "dbTable": "<%= $query_id %>",
    "fields": aoFields
    });

    $('#table-view').dataTable({
    "aoColumns": aoColumns,
    "aaData": aaData,
    "bDeferRender": true,
    "iDisplayLength": 100,
    "bScrollInfinite": true,
    "bScrollCollapse": true,
    "sScrollY": 600,
    "bJQueryUI": true,
    "sDom": "Tfrtip",
    "oTableTools": {
    "sRowSelect": "single",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor,
    "formButtons": [
    {
    "label": "Create",
    "className": "create",
    "fn": function (e) {
    this.submit();
    }
    },
    {
    "label": "Create & Add Another",
    "sButtonText": "Create & Add Another",
    "className": "create_next",
    "fn": function (e) {
    this.submit( function () {
    $('a.editor_create').click();
    }, null, null, false );
    }
    }
    ] },
    { "sExtends": "editor_edit", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    }
    });
    [/code]
    Now I see the two buttons I want (left button 'Create & Add Another'; right button 'Create') and the right button works as expected. It creates a new data row and closes the editor. But the left button does not. If you click it, a new row is created and the editor remains open, BUT you can't created another line. I am able to change the field values as expected (although I'd like to see them empty) but clicks on BOTH buttons have no effect. They're just doing nothing at all. Why is that?

    I also tried different code:
    [code]
    TableTools.BUTTONS.editor_create.formButtons.push({
    "label": "Create & Add Another",
    "className":"btn btn-link",
    "fn": function () {
    this.submit( function () {
    $('a.editor_create').click();
    }, null, null, false );
    }
    });

    editor = new $.fn.dataTable.Editor({
    "ajaxUrl": "ajax_dummy",
    "domTable": "#table-view",
    "idSrc": "0",
    "dbTable": "<%= $query_id %>",
    "fields": aoFields
    });

    $('#table-view').dataTable({
    "aoColumns": aoColumns,
    "aaData": aaData,
    "bDeferRender": true,
    "iDisplayLength": 100,
    "bScrollInfinite": true,
    "bScrollCollapse": true,
    "sScrollY": 600,
    "bJQueryUI": true,
    "sDom": "Tfrtip",
    "oTableTools": {
    "sRowSelect": "single",
    "aButtons": [
    { "sExtends": "editor_create", "editor": editor },
    { "sExtends": "editor_edit", "editor": editor },
    { "sExtends": "editor_remove", "editor": editor }
    ]
    }
    });
    [/code]
    and it's the same behaviour.

    Would you please tell me what I'm doing wrong?

    Regards,
    Mathias
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Can you link me to the page so I can take a look and see what is going wrong please? Thee is a bug in 1.2 about the button labelling, but I don't think it should effect the functions called.

    Allan
  • fabianrottfabianrott Posts: 30Questions: 1Answers: 0
    I got it. Found my brain searching easter eggs ^^.

    No, I'm new to web development and I didn't know the 'a.' in [code] this.submit( function () {
    $('a.editor_create').click();
    }, null, null, false );
    }[/code] stood for a HTML link class name. So I just used the great firefox web development tools, looked up the name of the class of my button, wrote this class name for 'a' and voila: it worked.

    Thanks for your help anyway.
    Mathias
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Nice one :-)

    Allan
This discussion has been closed.