Problem with table display with joint

Problem with table display with joint

yurispyyurispy Posts: 29Questions: 6Answers: 0

Hello
Following this example applied to my system I encounter a bug.
https://editor.datatables.net/manual/php/joins#Client-side

When the table is displayed, I have the column that corresponds to the join that does not appear.

If I create a recording I have the cell with the name.
I have no mistakes anywhere.
Only on the display of the table there is a column missing whereas it is well declared in my javascript columns: []

<script type="text/javascript" language="javascript" class="init">
    


var editor; // use a global for the submit and return data rendering in the examples

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "scripts/php_gestion_prix_produit.php",
        table: "#phyto_test",
        i18n: {
            create: {
                button: "Nouveau",
                title:  "Créer nouvelle entrée",
                submit: "Créer"
            },
            edit: {
                button: "Modifier",
                title:  "Modifier entrée",
                submit: "Actualiser"
            },
            remove: {
                button: "Supprimer",
                title:  "Supprimer",
                submit: "Supprimer",
                confirm: {
                    _: "Etes-vous sûr de vouloir supprimer %d lignes?",
                    1: "Etes-vous sûr de vouloir supprimer 1 ligne?"
                }
            },
            error: {
                system: "Une erreur s’est produite, contacter l’administrateur système"
            },
            multi: {
                title: "Plusieurs valeurs",
                info: "Les éléments sélectionnés contiennent des valeurs différentes pour cette entrée. Pour modifier et mettre tous les éléments pour cette entrée pour la même valeur, cliquez ou appuyez ici, sinon ils vont conserver leurs valeurs individuelles.",
                restore: "Annuler les modifications"
            },
            datetime: {
            previous: 'Précédent',
            next:     'Premier',
            months:   [ 'Janvier', 'Février', 'Mars', 'Avril', 'peut', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre' ],
            weekdays: [ 'Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam' ]
            }
        },
        fields: [ 
            {
                label: "produit_id:",
                name: "produit_prix.produit_id"
            }, {
                label: "produit:",
                name: "produit.produit"
            }, {
                label: "prix:",
                name: "produit_prix.prix"
            }, {
                label: "saison:",
                name: "produit_prix.saison"
            }, {
                label: "last_update:",
                name: "produit_prix.last_update"
            }
        ]
    } );
    
    // Activez une édition en ligne sur le clic d'une cellule de table
    $('#phyto_test').on( 'click', 'tbody td:not()', function (e) {
        editor.inline( this );
    } );


 
    // Modifier l'enregistrement
    $('#phyto_test').on( 'click', 'a.editor_edit', function (e) {
        e.preventDefault();
 
        editor
            .title( 'Modifier' )
            .buttons( { "label": "Modifier", "fn": function () { editor.submit() } } )
            .edit( $(this).closest('tr') );
    } );
 
    // Message de confirmation avant suppression via le lien
    $('#phyto_test').on( 'click', 'a._remove', function (e) {
        e.preventDefault();
 
        editor
            .title( 'Suppression' )
            .message( "Etes vous sur de vouloir supprimé cette ligne?" )
            .buttons( { "label": "Supprimer", "fn": function () { editor.submit() } } )
            .remove( $(this).closest('tr') );
    } );

    // Affichage du tableau
    
    var table = $('#phyto_test').DataTable( {
        dom: "frtp",
    //  ajax: "scripts/php_gestion_prix_produit.php",
        ajax: {
            url: "scripts/php_gestion_prix_produit.php",
            type: 'POST'
        },
        paging: true,
        "autoFill": false,
        language: { url: '/localisation/fr_FR.json' },
        "order": [[ 1, 'asc' ]],
        "displayLength": 15,
        "columnDefs": [
            { "visible": false, "targets": 1 },
            { targets: -1,
                data: "id",
                render: function(data, type, full){
                    return '<a class="button mini-button cycle-button editor_edit"><img src="images/edit.png"></a>  <a class="button mini-button cycle-button" href="supp_gestionnaire.php?get_table=observation&supp_id=' + full['id'] + '"><img src="images/1428776654_trashcan-delete2.png"></a>';
                }
            }
        ],
        columns: [
            { data: "produit_prix.produit_id" },
            { data: "produit.produit" },
            { data: "produit_prix.prix" },
            { data: "produit_prix.saison" },
            { data: "produit_prix.last_update" },
            { data: "produit_prix.ID" },
        ],

    } );
    var buttons = new $.fn.dataTable.Buttons(table, {
        buttons: [ { extend: "create", className: 'fluent-big-button new-toggle', editor: editor, text: "<span class='icon icon-observation'></span>Nouveau" },  ]
    }).container().appendTo($('#buttons'));
} );
$( "a" ).removeClass( "dt-buttons" );
$( "div" ).removeClass( "dt-buttons" );


</script>
<?php

/*
 * Example PHP implementation used for the index.html example
 */

// DataTables PHP library
include( "../Editor-PHP/php/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'produit_prix' )
    ->fields(
        Field::inst( 'produit_prix.produit_id'),
        Field::inst( 'produit.produit'),
        Field::inst( 'produit_prix.prix'),
        Field::inst( 'produit_prix.saison'),
        Field::inst( 'produit_prix.last_update')
          ->setValue( date('c') )
          ->getFormatter( 'Format::date_sql_to_format', 'jS F Y' ),
        Field::inst( 'produit_prix.id' )->set( false )
    )
    ->leftJoin( 'produit', 'produit.id', '=', 'produit_prix.produit_id' )
    ->process($_POST)
    ->json();
{"data":[{"DT_RowId":"row_1","produit_prix":{"produit_id":"1","prix":"999.0000","saison":"2018","last_update":"17th March 2019","id":"1"},"produit":{"produit":"19-0-33-0-0-0 EURALIS"}},
{"DT_RowId":"row_2","produit_prix":{"produit_id":"2","prix":null,"saison":"2018","last_update":null,"id":"2"},"produit":{"produit":"19-0-33-0-0-0 SRA"}},
{"DT_RowId":"row_3","produit_prix":{"produit_id":"3","prix":"0.2990","saison":"2018","last_update":null,"id":"3"},"produit":{"produit":"10-7-30-0-0-0 EURALIS"}},
{"DT_RowId":"row_4","produit_prix":{"produit_id":"4","prix":null,"saison":"2018","last_update":null,"id":"4"},"produit":{"produit":"10-15-27-0-0-0 SRA"}},
{"DT_RowId":"row_5","produit_prix":{"produit_id":"5","prix":null,"saison":"2018","last_update":null,"id":"5"},"produit":{"produit":"11-11-22-0-0-0 16SO3 Eurofertil"}},
{"DT_RowId":"row_6","produit_prix":{"produit_id":"6","prix":null,"saison":"2018","last_update":null,"id":"6"},"produit":{"produit":"11,5-23-23-0-0-0 S EURALIS"}},
{"DT_RowId":"row_7","produit_prix":{"produit_id":"7","prix":null,"saison":"2018","last_update":null,"id":"7"},"produit":{"produit":"13,5-0-45-0-0-0 SQM"}},
{"DT_RowId":"row_8","produit_prix":{"produit_id":"8","prix":null,"saison":"2018","last_update":null,"id":"8"},"produit":{"produit":"13,5-0-45-0-0-0 DUCLOS"}},
{"DT_RowId":"row_9","produit_prix":{"produit_id":"9","prix":null,"saison":"2018","last_update":null,"id":"9"},"produit":{"produit":"14,5-0-22,5-0-0-0 SQM"}},
{"DT_RowId":"row_10","produit_prix":{"produit_id":"10","prix":null,"saison":"2018","last_update":null,"id":"10"},"produit":{"produit":"8-28-0-0-0-0 anhydride phosphorique"}},
{"DT_RowId":"row_11","produit_prix":{"produit_id":"11","prix":"0.4024","saison":"2018","last_update":null,"id":"11"},"produit":{"produit":"14-48-0-0-0-0 polyphosphate SRA"}},

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    In your columns you have { data: "produit_prix.ID" },. Your data contains this:

                    "produit_prix": {
                        "produit_id": "1",
                        "prix": "999.0000",
                        "saison": "2018",
                        "last_update": "17th March 2019",
                        "id": "1"
                    },
    

    The variables are case sensitive. Try changing your column definition to this { data: "produit_prix.id" },.

    Kevin

  • yurispyyurispy Posts: 29Questions: 6Answers: 0

    What else can I put? is an "int" in sql and primary key

  • yurispyyurispy Posts: 29Questions: 6Answers: 0

    I have put in red what I want to appear in the display of the table.
    I don't understand why this doesn't work.

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765
    Answer ✓

    In line 109 above you are hiding the produit column with this code:

            "columnDefs": [
                { "visible": false, "targets": 1 },
    

    Remove the { "visible": false, "targets": 1 }, and the column will display in the table.

    Kevin

  • yurispyyurispy Posts: 29Questions: 6Answers: 0

    hannn ashamed of me, I forgot that it doesn't start at 1 but at 0...
    tank you very much

This discussion has been closed.