Modify a value with columns.data=null (Editor)

Modify a value with columns.data=null (Editor)

matmoutmatmout Posts: 6Questions: 3Answers: 0

Hi everybody,

I am using Editor but I have a question and I don't know if editor can do it.
Here is the probleme, I set my columns like this : (I only show you important things, if you need something else I can show you of course)

{ data: "ARTICLES_PRIX.AP_PRIX" },
{ data: null,
render: function ( data, type, row ) {
var prix = parseFloat(row.ARTICLES_PRIX.AP_PRIX);
var tva = parseFloat(row.ARTICLES_TVA.VALUE);
var prixTva = (prix*(1+tva)).toFixed(2);

return prixTva;
} 

},

So it work, I have one column with PRIX (price in french) and the second one with the price with the taxes (the calcul above)

What I want to do is when I modify the seconde column, it calculate the price and write it in the fist column
If I try it now I have the error : Uncaught Could not automatically determine field data. (logic, I set it to null)

I could be wonderfull if some could help me,
Thank you very much,
Sorry for bad english

This question has an accepted answers - jump to answer

Answers

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

    What I want to do is when I modify the seconde column, it calculate the price and write it in the fist column

    Would both those fields be in the Editor form, and both are editable? If so, you could dependent(), as that could be setup to modify the first value when the second is changed. Example here.

    Colin

  • matmoutmatmout Posts: 6Questions: 3Answers: 0

    Hi, thanks for the answer,
    The fact is that only the price without taxes is save (I also save the taxes value so I can calculate the price with taxe).
    What I want to do is to modify the price with taxes (wich is not saved in database) with dataTable Editor

    Yesturday I made something (I don't know if it's correct but I hate to be blocked like that)

    I change in ajax called php page :

    Field::inst( 'ARTICLES_PRIX.AP_PRIX', 'PRIX_TTC' )
    ->getFormatter( function ( $val, $data ) {
    $prix = $data['ARTICLES_PRIX.AP_PRIX'];
    $tva = $data['ARTICLES_TVA.VALUE'];
    $prixTva = ($prix*(1+$tva));
    return round($prixTva,2);
    } )
    ->validator( Validate::notEmpty( ValidateOptions::inst())),
    Field::inst( 'ARTICLES_PRIX.AP_PRIX' )
    ->validator( Validate::notEmpty( ValidateOptions::inst())),

    so now I have two fields : PRIX_TTC and ARTICLES_PRIX.AP_PRIX wich change the same value : ARTICLES_PRIX.AP_PRIX. (I add a getFormatter to display the calculated value)

    then I add in my js :

    editor.field( 'PRIX_TTC' ).input().on( 'keyup', function () {
    var tva = parseFloat(editor.field( 'ARTICLES_TVA.VALUE' ).val());
    var prixTTC=this.value;

        var prixHT=prixTTC/(1+tva);
        editor.field( 'ARTICLES_PRIX.AP_PRIX' ).val(prixHT.toFixed(2));
    

    } );

    So when I modify my field PRIX_TTC, it update ARTICLES_PRIX.AP_PRIX with the uncalculed price

    So it work when I modify one value but not with autoFill and I think it's not very beautifull so if you have an idea it would be awesome,

    Thanks again for the answer !

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    As I always say, if it works, it works :)

    Colin

  • matmoutmatmout Posts: 6Questions: 3Answers: 0

    Ahah, thanks ! :)

This discussion has been closed.