Inline editing with submit button and remove

Inline editing with submit button and remove

mak1mak1 Posts: 25Questions: 13Answers: 1

Hi Allan,

I have been struggling for a few hours on the following use case. I am using inline editing with a submit button:
https://editor.datatables.net/examples/inline-editing/submitButton.html

However once the submit button has been pressed, I want that row to be removed from the datatable without warning the user. I thought a simple server redirect from the python server side will do as the page would reload and the row won't be there. However instead of redirecting, the inline button just shows that it's loading and then it stops loading and the row remains.

I want to do something like this

       editor.inline( this, {
            buttons: { label: 'Assign', fn: function () { this.submit();  this.remove(this,false); } }
        } );

but this this.remove(this,false) doesn't work.

Any suggestions of other ways? I am not using the datatable main buttons or any selection mechanism. Here's part of my code

$(document).ready(function() {
var editor; // use a global for the submit and return data rendering in the examples

 editor = new $.fn.dataTable.Editor( {
        table: "#tablex",
        ajax: "/holder_api",
        idSrc: "request",

         fields: [

           {
                label: "Holder",
                name: "holder.value",
                "type": "select2",
                "options":{{=asis(holdersJson)}}
            }

        ]
    } );




    // Activate an inline edit on click of a table cell
 $('#tablex').on( 'click', 'tbody td', function (e) {



        editor.inline( this, {
            buttons: { label: 'Assign', fn: function () { this.submit();  } }
        } );

    } );



 var table =   $('#tablex').DataTable( {

    data:  {{=asis(results)}},
    "scrollX": true,
 dom: 'lTfrtip',
  rowId: 'request',
    columns: [
        { data: 'request',"visible": false},
        { data: 'holder.label',editField: 'holder.value',title: '{{=column_labels['holder']['label']}}', defaultContent: ""}
    ]

    } );




$('#tablex').dataTable().fnAdjustColumnSizing( false );





} );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,812Questions: 1Answers: 10,516 Site admin
    Answer ✓

    I want that row to be removed from the datatable without warning the user.

    Have the server return { "data": [] } which will cause Editor to think that the row no longer exists on the server-side (or that it doesn't meet whatever filtering requirements there are due to the updated data) and remove it.

    Allan

  • mak1mak1 Posts: 25Questions: 13Answers: 1

    Yeap that worked :) thank you

This discussion has been closed.