Inline edit not changing values immediately on losing focus.

Inline edit not changing values immediately on losing focus.

davykiashdavykiash Posts: 35Questions: 13Answers: 1

Hello,

I have an inline editor that changes the datasource (Localstorage) but does not change immediately. Only when I reload the page does the change reflect. My gut feeling is that I should be puting a draw function somewhere but I dont know where exactly.

Before

On Inline edit

After I remove the focus from edit field

After I refresh the whole page

The code for my inline editor looks like this

$('#sales_table').on( 'click', 'tbody td:not(:first-child)', function (e) {
    editor.inline( this);               
} );

And my editor

editor = new $.fn.dataTable.Editor( {
table: "#sales_table",
fields: 
    [                           
        {
            label: "Quantity:",
            name: "so_quantity"
        }                                                       
    ],
ajax: function ( method, url, d, successCallback, errorCallback ) 
    {
        
        var output = { data: [] };
        
        if ( d.action === 'edit' ) {
            
             // Update each edited item with the data submitted
            
            $.each( d.data, function (id, value) {
                value.DT_RowId = id;
                $.extend( sales_local_data[ id ], value );
                output.data.push( sales_local_data[ id ] );
            } );
            
            
        }
        
        // Store the latest `todo` object for next reload
        localStorage.setItem( 'sales_local_data', JSON.stringify(sales_local_data) );

        
        // Show Editor what has changed
        successCallback( sales_local_data );

    }                                       
});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,824Questions: 1Answers: 10,130 Site admin

    Change editor.inline( this); to be:

    editor.inline( this, {
      onBlur: 'submit'
    } );
    

    By default if you just blur the field (i.e. it loses focus without pressing return) it won't save. That option will make it do so.

    Allan

  • davykiashdavykiash Posts: 35Questions: 13Answers: 1
    edited October 2017

    @allan I have done the change. No effect. Also when I enter return there is no effect. Would a whole table redraw work?

  • allanallan Posts: 61,824Questions: 1Answers: 10,130 Site admin
    Answer ✓

    Ah - okay. That suggests that the Ajax override that is being used isn't returning what Editor expects.

    successCallback( sales_local_data );
    

    could you change that to be:

    successCallback( output );
    

    please?

    Allan

  • davykiashdavykiash Posts: 35Questions: 13Answers: 1

    @allan Awesome!

This discussion has been closed.