Import CSV Multirow Has The Same Value after SetValue on PreCreate

Import CSV Multirow Has The Same Value after SetValue on PreCreate

Showa Indonesia MfgShowa Indonesia Mfg Posts: 7Questions: 3Answers: 0
edited November 2021 in DataTables 1.9

Description of problem:

Programming language: PHP

I'm using import csv via datatable and need process in some column before insert to table. The process is to get Description by Part No.

But when using the preCreate event, the inserted description value is always the same value for all rows. It seems like the setValue() is updating all rows with the last value get by getPartInfo() function.

Is there any solution ?

Code

                ->on('preCreate', function($editor, &$values) {
                    $partInfo = $this->getPartInfo($values['PART_NO'], $values['CONTRACT']);
                    $editor
                        ->field('DESCRIPTION')
                        ->setValue($partInfo['Description']);

Result

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    It seems like the setValue() is updating all rows with the last value get by getPartInfo() function.

    That is correct. It sets the value to use for the field, and that is applied to the field instance, rather than at a row level.

    What to do here is modify the value in the $values array (since it is passed by reference, as noted by the &) - so you can do:

    $values['DESCRIPTION'] = $partInfo['Description'];
    

    Allan

  • Showa Indonesia MfgShowa Indonesia Mfg Posts: 7Questions: 3Answers: 0

    Great, solved!

    Thank you for your support.

Sign In or Register to comment.