The line disappears after create or edit

The line disappears after create or edit

SWATswatSWATswat Posts: 83Questions: 0Answers: 0
edited August 2018 in Editor

Hello

The line disappears after create or edit, to see it, I need to refresh the web page.
An idea about the cause of this behavior ?

Thank you.
Datatable editor v1.7.2

Replies

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769

    Sounds like your server script might not be returning the expected response for create and edit. Please see this doc page for information of what is expected:
    https://editor.datatables.net/manual/server#Example-data-exchanges

    Kevin

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0

    Hi Kevin,
    Thanks for your response, but the version 1.5.6 of the datatable editor worked correctly before updating in 1.7.2.

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769

    There is much to go on for use to help. I would start by validating the data in the responses for edit and create. Do you get any errors in the browser's console?

    Can you post a link to your page or a test case showing the issue?

    Kevin

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0
    edited August 2018

    Parameter of browser's console after edit :

    action  edit
    data[row_720][date_prevu]   2018-06-01
    data[row_720][heure_arrivee]    00:00:00
    data[row_720][heure_debut_dechargement] 00:00:00
    data[row_720][heure_depart] 00:00:00
    data[row_720][heure_fin_dechargement]   00:00:00
    data[row_720][heure_presentation]   08:00:00
    data[row_720][heure_prevu]  10:00:00
    data[row_720][immatriculation]  dsv7700571
    data[row_720][nbre_palette] 88
    data[row_720][poc_attendu]  0
    data[row_720][poc_recu] 0
    data[row_720][reservation_transporteur] OUI
    data[row_720][transporteur_boat_ok] DSV2
    

    Response of of browser's console after edit :

    {"data":[]}
    

    actually there may be a problem.

    My code HTML page :

    <script type="text/javascript" language="javascript" class="init">
    var editor; 
    
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
                
            ajax: "staff_result_Date_archives.php",
            table: "#archive",
            fields: [{
                    label: 'Date prevue',
                    name:  'date_prevu',
                    type:  'datetime',
                    def:        function () { return new Date(); },
                                    
                },
                {
                    label: "Heure prevue",
                    name: "heure_prevu",
                    type:  'datetime',
                    format: 'HH:mm:ss',
                    fieldInfo: '24 hour clock format with seconds',
                    opts: {
                        minutesIncrement: 05,
                        secondsIncrement: 30
                    }
                },
                {
                    label: "Transporteur",
                    name: "transporteur_boat_ok"
                },
                {
                    label: "Immatriculation",
                    name: "immatriculation"
                },
                {
                    label: "Nombre palette",
                    name: "nbre_palette"
                },
                {
                    label: "Heure de presentation",
                    name: "heure_presentation",
                    type:  'datetime',
                    format: 'HH:mm:ss',
                    fieldInfo: '24 hour clock format with seconds',
                    opts: {
                        minutesIncrement: 05,
                        secondsIncrement: 30
                    }
                                    
                },
                {
                    label: "Heure arrivee",
                    name: "heure_arrivee",
                    def:   function () { return new Date(); },
                    type: "datetime",
                    format: "HH:mm:ss",
                    attr: {
                      "readonly": true,
                      "autocomplete": "off"
                    }
                                                    
                },
                {
                    label: "Heure debut dechargement",
                    name: "heure_debut_dechargement",
                    type:  'datetime',
                    format: 'HH:mm:ss',
                    fieldInfo: '24 hour clock format with seconds',
                    opts: {
                        minutesIncrement: 05,
                        secondsIncrement: 30
                    }
                },
                {
                    label: "Heure fin dechargement",
                    name: "heure_fin_dechargement",
                    type:  'datetime',
                    format: 'HH:mm:ss',
                    fieldInfo: '24 hour clock format with seconds',
                    opts: {
                        minutesIncrement: 05,
                        secondsIncrement: 30
                    }
                },
                {
                    label: "Heure depart",
                    name: "heure_depart",
                    type:  'datetime',
                    format: 'HH:mm:ss',
                    fieldInfo: '24 hour clock format with seconds',
                    opts: {
                        minutesIncrement: 05,
                        secondsIncrement: 30
                    }
                },
                {
                    label: "Reservation BOAT",
                    name: "reservation_transporteur",
                    def: "NON",
                    type: "readonly"
                    
                },
                {
                    label: "POC recu",
                    name: "poc_recu"
                },
                {
                    label: "POC attendu",
                    name: "poc_attendu"
                }
            ]
        } );
        
    
    
        $('#archive').DataTable( {
            dom: 'Bfrtip',
            ajax: "staff_result_Date_archives.php",
            columns: [{
                    "data": "date_prevu"
                },
                {
                    "data": "heure_prevu"
                },
                {
                    "data": "transporteur_boat_ok"
                },
                {
                    "data": "immatriculation"
                },
                {
                    "data": "nbre_palette"
                },
                {
                    "data": "heure_presentation"
                },
                {
                    "data": "heure_arrivee"
                },
                {
                    "data": "heure_debut_dechargement"
                },
                {
                    "data": "heure_fin_dechargement"
                },
                {
                    "data": "heure_depart"
                },
                {
                    "data": "reservation_transporteur"
                },
                {
                    "data": "poc_recu"
                },
                {
                    "data": "poc_attendu"
                }
                
            ],
            select: true,
            buttons: [
                { extend: 'create', editor: editor },
                { extend: 'edit',   editor: editor },
                
                {
                    extend: 'collection',
                    text: 'Export',
                    buttons: [
                        'copy',
                        'excel',
                        'csv',
                        'pdf',
                        'print'
                    ]
                }
            ]
        } );
    } );
    

    Server side php page

    Editor::inst( $db, 'archives_reception', 'id' )
        ->fields(
            Field::inst( 'date_prevu' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'heure_prevu' )->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'transporteur_boat_ok' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'immatriculation' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'nbre_palette' )->validator( 'Validate::numeric' ),
            Field::inst( 'heure_presentation' )->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_arrivee' )
                ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_debut_dechargement' )->validator( 'Validate::required' )
              ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_fin_dechargement' )->validator( 'Validate::required' )
              ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'heure_depart' )->validator( 'Validate::required' )
              ->validator( Validate::dateFormat(
                    'H:i:s',
                    ValidateOptions::inst()
                        ->allowEmpty( false )
                ) ),
            Field::inst( 'reservation_transporteur' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'poc_recu' )->validator( 'Validate::numeric' ),
            Field::inst( 'poc_attendu' )->validator( 'Validate::numeric' )
        )
        ->where('date_prevu', $MyDate_1)
        ->process( $_POST )
        ->json();
    

    Thank you for your help

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0

    Hello,

    I have been looking all day and I can not find where the problem comes from.
    I have another application that does not use Datatable with data back in Json and it works, so I can exclude the problem from the server.

    I really need your help, I can provide you the link but by email only please (prod server).

    Thank you in advance.

  • allanallan Posts: 61,715Questions: 1Answers: 10,107 Site admin

    The row is disappearing because of the JSON return from the server: {"data":[]}. That means that there was no row to show after the edit, and thus Editor (on the client-side) removes the row.

    The most common cause for this is that the condition (where()) applied is not met after the edit - i.e. the row has been filtered out. Does date_prevu == $MyDate_1 after the edit? My guess is not. What is $MyDate_1 at that point and what is the value in the db?

    Allan

  • SWATswatSWATswat Posts: 83Questions: 0Answers: 0
    edited August 2018

    Hello Allan,
    You're a genius, I'm an idiot.
    Actually after loading the variable $ MyDate_1 = "date_prevu" for loading the page, I reset it $ MyDate_1 = "" so the return to display the modification is null.

    After removing this line datatable works normally.

    Thank you very much.
    And I learned something positive tonight, the php file is browsed a second time after the update.

    Being a beginner, I learn every day.

    Thank you very much Allan.

This discussion has been closed.