Row reordering where the ajax data source has left join

Row reordering where the ajax data source has left join

crush123crush123 Posts: 417Questions: 126Answers: 18

I am using row reordering without any issues where i have a single table in the ajax source, but I get an error thrown on preCreate and postRemove if there is a left join.

I tried specifying the table in the code but get the error Notice: Undefined index: refgallery.ListOrder in filename.php on line 41

->on( 'preCreate', function ( $editor, $values ) {
    // On create update all the other records to make room for our new one
    $editor->db()
        ->query( 'update', 'refgallery' )
        ->set( 'refgallery.ListOrder', 'refgallery.ListOrder+1', false )
        ->where( 'refgallery.ListOrder', $values['refgallery.ListOrder'], '>=' )
        ->exec();
} )

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Have you set Editor up to submit all values (form-options - see the submit option)? If not, then it is only going to submit the values which have a new value, which might explain the issue. If not that, then can you link to a test case please.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited November 2015

    ..unless its my syntax

    i have tried this with a table, no left join, but declaring the table name into the editor instance

    eg the following code works...

    <?php 
    // Build our Editor instance and process the data coming from _POST
      $data = Editor::inst( $db, 'refsection', 'SectionID' )//table name and PKey(defaults to ID)
    ->field(
        Field::inst( 'SectionID' ),
        Field::inst( 'SectionDescription' )
          ->validator( 'Validate::notEmpty'), 
        Field::inst( 'ListOrder' )
          ->validator( 'Validate::numeric')
        )
    
    ->on( 'preCreate', function ( $editor, $values ) {
        // On create update all the other records to make room for our new one
        $editor->db()
            ->query( 'update', 'refsection' )
            ->set( 'ListOrder', 'ListOrder+1', false )
            ->where( 'ListOrder', $values['ListOrder'], '>=' )
            ->exec();
    } )
    ->on( 'postRemove', function ( $editor, $id, $values ) {
        // On remove, the sequence needs to be updated to decrement all rows
        // beyond the deleted row
        $editor->db()
            ->query( 'update', 'refsection' )
            ->set( 'ListOrder', 'ListOrder-1', false )
            ->where( 'ListOrder', $values['ListOrder'], '>' )
            ->exec();
    } )
    
    ->process( $_POST )
    ->data();
    
    echo json_encode( $data );
    ?>
    

    but this code throws the error, as described earlier

    <?php 
    // Build our Editor instance and process the data coming from _POST
      $data = Editor::inst( $db, 'refsection', 'SectionID' )//table name and PKey(defaults to ID)
    ->field(
        Field::inst( 'refsection.SectionID' ),
        Field::inst( 'refsection.SectionDescription' )
          ->validator( 'Validate::notEmpty'), 
        Field::inst( 'refsection.ListOrder' )
          ->validator( 'Validate::numeric')
        )
    
    ->on( 'preCreate', function ( $editor, $values ) {
        // On create update all the other records to make room for our new one
        $editor->db()
            ->query( 'update', 'refsection' )
            ->set( 'refsectionListOrder', 'refsectionListOrder+1', false )
            ->where( 'refsectionListOrder', $values['refsection.ListOrder'], '>=' )
            ->exec();
    } )
    ->on( 'postRemove', function ( $editor, $id, $values ) {
        // On remove, the sequence needs to be updated to decrement all rows
        // beyond the deleted row
        $editor->db()
            ->query( 'update', 'refsection' )
            ->set( 'refsection.ListOrder', 'refsection.ListOrder-1', false )
            ->where( 'refsection.ListOrder', $values['refsection.ListOrder'], '>' )
            ->exec();
    } )
    
    ->process( $_POST )
    ->data();
    
    echo json_encode( $data );
    ?>
    
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Ah - I see the issue - thanks for the link by PM.

    The issue is with how the parameter is being accessed:

    $values['refgallery.ListOrder']

    It should actually be:

    $values['refgallery']['ListOrder']
    

    i.e. it is really a dimensional array.

    You could add print_r( $values ) if you wanted to see the full data structure.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    thanks Allan, - my syntax again !

    Love this plug in.

  • testnickboontestnickboon Posts: 0Questions: 0Answers: 0

    Thnx, solved also my problem

  • testnickboontestnickboon Posts: 0Questions: 0Answers: 0

    Thnx, solved also my problem

This discussion has been closed.