Problem with inline editing + serverside

Problem with inline editing + serverside

ecartierdijonecartierdijon Posts: 1Questions: 1Answers: 0

Hi,
First, congratulations Allan for this piece of soft, really useful! I am stuck with inline editing in serverside mode. Here are the relevant codes

main php file (relevant parts) :

            <div class="row" style="width:95vw">
                    <div class="card"  style="width:95vw">
                        <div class="card-body">
                            <table class="datatable table" cellspacing="0" id="exampleNeo"  style="width:95vw">
                                <thead>
                                    <tr>
                                        <th>Lexie</th>
                                        <th>Cat. synt.</th>
                                        <th>Cat. sem.</th>
                                    </tr>
                                    <tr>
                                        <th>Lexie</th>
                                        <th>Cat. synt.</th>
                                        <th>Cat. sem.</th>
                                    </tr>
                                </thead>
                                <tfoot>
                                    <tr>
                                        <th>Lexie</th>
                                        <th>Cat. synt.</th>
                                        <th>Cat. sem.</th>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
            </div>

javascript file (relevant parts):

editorNeo = new $.fn.dataTable.Editor( {
        ajax: {url:"php/neo-db_srv.php?lang="+languageW,type:"POST"},
        table: "#exampleNeo",
        lang:languageW,
        fields: [
            {   
                label: "Lexie&nbsp;<span id='infofield' class='icon fa fa-info-circle infofield'></span>",
                name: "termes_copy.terme",
                fieldInfo:"<div class='alert alert-info alert-dismissible' role='alert'>Forme canonique de la lexie</div>"
            },
            {
                label: "Partie du discours&nbsp;<span id='infofield' class='icon fa fa-info-circle infofield'></span>",
                name: "termes_copy.cat_synt",
                type: "select",
                placeholder:"Sélectionnez une partie du discours",
                fieldInfo:"<div class='alert alert-info alert-dismissible' role='alert'>Partie du discours du néologisme</div>"
            },          
            {
                label: "Hyperclasse&nbsp;<span id='infofield' class='icon fa fa-info-circle infofield'></span>",
                name:"termes_copy.hyperclass",
                type: "select",
                placeholder:"Sélectionnez une hyperclasse sémantique",
                fieldInfo:"<div class='alert alert-info alert-dismissible' role='alert'>Hyperclasse sémantique du néologisme</div>"
            },
        ],
    } );

// inline editing
    $('#exampleNeo').on( 'click', 'tbody td.editable', function (e) {
        editorNeo.inline( this, {
                submit:"changed",
                submitOnBlur: true,
                onFieldError:"focus"
        } );
    } );

// datatable
var table = $('#exampleNeo').DataTable( {
        dom: '<B>lrtip',
        fixedHeader: true,
        scrollY: '150vh',
            scrollCollapse: true,
        orderCellsTop: true,
        processing:true,
        serverSide:true,
        search: {regex: true},
                ajax:{url:"php/neo-db_srv.php?lang="+languageW,type:"POST"},
        lengthMenu: [[10, 25, 50, 100,  -1], [10, 25, 50, 100, "Tous"]],
        lengthChange: true,
        select:true,
        columns: [
        { data: "termes_copy.terme" },
    { data: "synt_cat_def.cat_synt", editField: "termes_copy.cat_synt", name: "termes_copy.cat_synt", className: 'editable' },

    { data: "classe_def.classe", editField: "termes_copy.hyperclass", name: "termes_copy.hyperclass", className: 'editable' },
        ],
        select: {
            style:    'os',
            selector: 'td:first-child'
        },
} );

server side php file:

Editor::inst( $db, 'termes_copy'  )
    ->fields(

        Field::inst( 'termes_copy.terme' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'termes_copy.cat_synt' )
            ->options( 'synt_cat_def', 'id', 'cat_synt' )
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'synt_cat_def.cat_synt' ),

        Field::inst( 'termes_copy.hyperclass' )
            ->options( 'classe_def', 'id', 'classe' )
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'classe_def.classe' ),
    )
    ->on( 'preCreate', function ( $editor, $values ) {
        $editor
            ->field( 'termes_copy.auteur' )
            ->setValue( $_SESSION['user'] );     
    } )
    ->on( 'preEdit', function ( $editor, $values ) {
        $editor
            ->field( 'termes_copy.last_update_author' )
            ->setValue( $_SESSION['user'] );
    })
    ->leftJoin( 'synt_cat_def', 'synt_cat_def.id', '=', 'termes_copy.cat_synt' )
    ->leftJoin( 'classe_def', 'classe_def.id', '=', 'termes_copy.hyperclass' )
    ->process( $_POST )
    ->json();

In client mode, the inline editing works fine, but in server mode, it does not update the field and get stuck, and the json response is really strange, as it indicates a fieldError on the other field (for example, if i modify synt_cat_def.cat_synt it indicates a bad value for termes_copy.hyperclass) :

{"fieldErrors":[{"name":"termes_copy.hyperclass","status":"This value is not valid"}],"data":[]}

Additionnally, the problem occurs only if no initial values are there for both fields (default value in db table is null), I can inline edit normally when values are there. Do you have any idea? Thanks in advance!
Emmanuel

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Change:

    editorNeo.inline( this, {
    

    to be:

    editorNeo.inline( table.cell(this).index(), {
    

    This example demonstrates that and explains why.

    Allan

This discussion has been closed.