Undefined Index when using inline editing

Undefined Index when using inline editing

Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

Him,
I get the error undefined index when using inline editing , I know where the error is coming from but dont know how to correct it.

Fromt he client side, I use this code for editor

editor = new $.fn.dataTable.Editor( {
        ajax: "/Editor/Editor-1.9.5/controllers/xxx.php",
        table: "#contracts",
        fields: [ 

         {
                label: "Product id:",
                name: "product_id_fk"

            },
          {
                label: "opt one price:",
                name: "opt_one_price"
            }, {
                label: "opt two price:",
                name: "opt_two_price"
            }             
            ]
    } );

and on the server side i use ValidateEdit function to update the database

    ->on( 'validatedEdit', function ( $editor, $id, $values ) use ( $db ) {
         $db->raw()

  ->bind( ':opt_one_price',          $values["opt_one_price"] )
  ->bind( ':opt_two_price',          $values["opt_two_price"] )

  ->exec( 'UPDATE contracts a
       INNER JOIN products b    ON    a.product_id_fk = b.product_id
              SET a.opt_one_price        = :opt_one_price,
                  a.opt_two_price        = :opt_two_price

            WHERE a.product_id_fk   = :product_id_fk 
            AND a.start_date   = :start_date');
    })

When using the normal editing with edit button(edit window popups up) it works fine. However with the inline edit , if I edit one field for example if I edit the opt_one_price , it shows me undefined index opt_two_price
Which means the editor is looks for both fields to be edited or at least get the value from both fields on edit.
Please give me some ideas to overcome this problem.

Thank you

Answers

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

    The easiest way is to set all for the submit option in the form-options - see example here. . That way all the row's data will be sent back to the server on the inline edit.

    Colin

  • Khalid TeliKhalid Teli Posts: 251Questions: 71Answers: 0

    @colin Happy new year.

    Thank you, that works perfect.

This discussion has been closed.