New Create Button

New Create Button

ladbrokeladbroke Posts: 2Questions: 1Answers: 0

Hi, I would like to add a new create button, but instead of the modal form opening, I just want a row created with the default values for each field. There are no mandatory fields in my form, so currently I can click 'New' then click submit and it will create a row, but that's obviously more long winded than it needs to be!

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ladbroke ,

    You could do something like this here. That one also goes straight into inline editing, but you can remove that by deleting the postCreate code.

    Cheers,

    Colin

  • ladbrokeladbroke Posts: 2Questions: 1Answers: 0

    Thanks Colin, I've taken what you kindly provided as an example. I'm trying to put it into a function, and I'm making a pigs ear of it, what I have still causes the modal to open it looks like this:

    new $.fn.dataTable.Buttons(table, [{
        extend: "create",
        text: "make empty",
        action: function(e, dt, node, config) {
            empty = true;
            editor.create().set('position', 'default position').submit();
        }
    }]);
    
    table
        .buttons()
        .container()
        .appendTo($('#createempty'));
    editor.on('postCreate', function(e, json, data, id) {
        if (empty) {
            editor.inline(table.cell('#' + id, 0).node());
        }
    
        empty = false;
    });
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ladbroke ,

    It may because you've got an array around the button. If you look at the last example on the Buttons page, you'll see it doesn't have it there.

    If still no joy, would you be able to modify my example so that it shows the problem,

    Cheers,

    Colin

This discussion has been closed.