Cannot access label of a dropdown select form tables

Cannot access label of a dropdown select form tables

PolonePolone Posts: 3Questions: 1Answers: 0

Hi,
sorry but I am not able to display nome and cognome (name and surname) in the child data table "partecipanti" of the master table "eventi" (events). Instead in the editor box the select dropdown displays everything fine and correct. But the table show the correct Id but not the name and surname. In the json code, nome and cognome stays in the array "options" but I can't access this data in any way I understand. I cannot figure why, can you help please to find the solution, I,m going crazy, thank you very much,

Paolo

Link to the app site:
https://www.palmapaolo.it/aa/partecipanti/

Here the php code from server side:

           Field::inst( 'partecipanti.id_utente' ),
           ->options( Options::inst()
           ->table( 'anagrafica' )
           ->value( 'id' )
           ->label( array('nome', 'cognome') )
           ->render( function ( $row ) {
               return $row['nome'].' ('.$row['cognome'].')';
           } )
       ),

Here the json answer:

{"data":
[{"DT_RowId":"row_5","partecipanti":{"id_utente":10,"dataiscrizione":"Wed, 2 Aug 23","presente":0,"incarico":5,"id_evento":4,"note":"Terza nota"},
"incarichi":{"incarico":"Dir. Corso"}},
{"DT_RowId":"row_6","partecipanti":{"id_utente":12,"dataiscrizione":"Tue, 1 Aug 23","presente":0,"incarico":1,"id_evento":4,"note":""},
"incarichi":{"incarico":"Partecipante"}}],
"options":
{"partecipanti.id_utente":[{"label":"Elettra (Officine Grafiche)","value":12},{"label":"Franco (Gelli)","value":13},{"label":"Gennaro (Palazzo)","value":8},{"label":"Gino (Faggi)","value":10},{"label":"Mario (Rossi)","value":11},{"label":"Simona (Ventura)","value":9}],
"partecipanti.incarico":[{"label":"Assistente","value":6},{"label":"Dir. Corso","value":5},{"label":"Docente","value":2},{"label":"Moderatore","value":4},{"label":"Partecipante","value":1},{"label":"Relatore","value":3},{"label":"Resp. Org.","value":7}]},
"files":[]}

Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Answers

  • rf1234rf1234 Posts: 2,993Questions: 87Answers: 421
    edited August 2023

    This

    ->render( function ( $row ) {
            return $row['nome'].' ('.$row['cognome'].')';
        } )
    

    is just for rendering name and cognome as options in Editor. It has no significance for the display of those fields in your data table.
    You chose to display the user id in your data table.

    To fix this:
    Select nome and cognome as fields in your PHP code as separate field instances and replace the user id in your data table with those two new fields.

  • PolonePolone Posts: 3Questions: 1Answers: 0

    Thank you rf1234,

    I made as you suggested, you can see the results. Now I have the correct data in the table, but I have, in the select dropdown, only the name (nome). And I should have nome + cognome.

    This is the php code:

    Field::inst( 'partecipanti.id_utente' )
    ->options( Options::inst()
    ->table( 'anagrafica' )
    ->value( 'id' )
    ->label( 'nome' )
    )->validator( Validate::dbValues() ),
    Field::inst( 'anagrafica.nome' ),
    Field::inst( 'anagrafica.cognome' ),

    This is for the table:
    { data: null,
    render: function(data, type, row) {
    return row.anagrafica.nome + ' ' + row.anagrafica.cognome;
    }
    },

    But, how to set the editor code to have nome + cognome in the dropdown list with the same id? (instead of nome without cognome)

    Thank you for helping

  • PolonePolone Posts: 3Questions: 1Answers: 0

    solved this way server side,
    thank a lot.
    Bye

    ->label( array('name', 'country') )

  • rf1234rf1234 Posts: 2,993Questions: 87Answers: 421

    but I have, in the select dropdown, only the name (nome). And I should have nome + cognome.

    Right because you changed your options instance which you shouldn't have.

    Just use the options instance that you already had:

    ->render( function ( $row ) {
            return $row['nome'].' ('.$row['cognome'].')';
        } )
    
Sign In or Register to comment.