Dynamic button won't show up - what am I doing wrong here?

Dynamic button won't show up - what am I doing wrong here?

resqonlineresqonline Posts: 58Questions: 14Answers: 0

I use a table (called: bookingstable) on a different page, where I add an extra class to perform some functionality (like a search based on a form input on that page). All the other actions in this function are executed, only the extra added button wont show up and I cannot for the life of me figure out why?

if ( $("#bookingstable").hasClass('termine') ) {
// this extra button won't show up:
    bookingstable.button().add( 0, {
        extend: 'edit',
        text: 'Cancel course',
        editor: 'canceleditor',
    } );
// all of these do what they should do:
    bookingsearch = $('div[data-name="kursnummer"]').find(':input').val();
    bookingstable.column(1).search(bookingsearch).draw();
    bookingeditor.on( 'initCreate', function() {
        bookingeditor.field('kurs_id').val( bookingsearch );
    });
}

The table itself is initilaised with var bookingstable = $("#bookingstable").DataTable({...});

Answers

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954
    edited January 2023

    I use a table (called: bookingstable) on a different page,

    Are you executing this code from a different web page?

    I would start by debugging the code starting at the if statement to see what its doing. One thing is editor: 'canceleditor', should probably be editor: canceleditor,. canceleditor should be the Editor instance variable not a string.

    If you need help debugging then we will need to see the problem. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • resqonlineresqonline Posts: 58Questions: 14Answers: 0

    oh, I didn't notice the string with the editor - I changed that, however the button is still not showing.

    As I said: all other things inside this if statement are executed, that's why I don't know where to start to look - I thought maybe I had called that button().add() wrong, but I double-checked and didn't find anything wrong with it.
    I am using the latest versions of everything https://debug.datatables.net/etuyeb
    I set up a test case later.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Can you link to a page showing the issue please? The button().add() call looks fine and appears to work okay in this trivial little example. I think I'd need to be able to trace the broken code through to see what is going wrong.

    Allan

  • resqonlineresqonline Posts: 58Questions: 14Answers: 0

    @allan I cannot show you the page, it's on a backend page unfortunately.

    I've put my whole Script in a gist, on line 1487 I have the function to add the button if the table has the extra class https://gist.github.com/resqonline/7d2665fc071adb48e51cb9aa9bea393e#file-datatables-functions-js-L1487
    I've tried with an index number, null and undefined, but nothing showed up.

    This is the HTML part of the table display: https://gist.github.com/resqonline/e41033c0bdc8dc7d5215591c7ea0f08c
    and this is how it looks like https://resq.online/cloud/index.php/s/XQJLPQkJobXwRcJ

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    I'm not immediately seeing anything to indicate why the button wouldn't be getting displayed. Are you able to modify the example I linked to, to show the issue so I can debug it?

    Allan

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    I looked at the code. Nothing stands out as a problem. I used your code to create this test case:
    http://live.datatables.net/guwafemu/346/edit

    The test case works as expected and adds the button for the canceleditor. Can you update the test case to show the issue?

    Kevin

  • resqonlineresqonline Posts: 58Questions: 14Answers: 0

    @kthorngren Thank you for this example and as I see from your code it should work as expected - I am really at a loss, why it won't do that in my code. :/

    @allan If I know what the issue is I could show it. I really have no idea, why it works as shown in the example by kthorngren, and why it wouldn't do anything in my own code. If you don't see anything obvious, I guess I just have to try to find any missing piece on my end.

    Thank you both for your help. If I find anything, I'll let you know!

Sign In or Register to comment.