Dependent inline

Dependent inline

hendrikwjyhendrikwjy Posts: 8Questions: 1Answers: 0

Hi, i use dependent with inline, i have qty, price, and subtotal field.
When i change the qty field, i want to display the subtotal, but the subtotal does not change

    editor.dependent( 'qty', function ( val, data, callback ) {
        var price = editor.field('price').val();
        var subtotal = val * price;
        return  {
                    "values": {
                        "subtotal": subtotal,
                    },
                };
    } );            

Replies

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    Inline editing doesn't really work with dependent fields since you can only have a single field showing as editable at a time when using inline editing.

    So setting the value of any other field is redundant since it wouldn't be visible.

    What I would suggest for this sort of calculation is to use columns.render (overview documentation) - when the data is submitted to the server it will then update the value in the other column.

    Regards,
    Allan

  • hendrikwjyhendrikwjy Posts: 8Questions: 1Answers: 0

    Hi allan, thanks for your reply, and now i have a problem
    i render the subtotal calculation

    "render": function ( data, type, row, meta ) {
    return row.qty*row.price;
    }

    and i want to format the number using

    "render": $.fn.dataTable.render.number( ',', '.', 2 )

    how can i combine these two render in a column?

    Thanks

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin

    Use:

    var renderer =  $.fn.dataTable.render.number( ',', '.', 2 ).display;
    
    "render": function ( data, type, row, meta ) {
      return renderer( row.qty*row.price );
    }
    

    Allan

This discussion has been closed.