Add multiple value in column

Add multiple value in column

pettedemonpettedemon Posts: 38Questions: 6Answers: 0
edited October 2019 in DataTables 1.10

Hi,
I haver a server side Datatables.
when I render my table I want to tie more value in one column.
So I have:
name + email + city

in the script I have just

`

   "columns": [
        {
          "className":      'details-control',
          "orderable":      false,
          "data":           null,
          "defaultContent": '',

        },

        {
            "data": "ora_appuntamento",

        },
        {
            "data": "numero_telefono",

        },

    ],`

I want add a column with the multiple value. So how can I do it?
Thanks

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
  • David@QuantumDavid@Quantum Posts: 36Questions: 4Answers: 2

    Hey @pettedemon , I haven't tested this at all, but the excerpt below should give you a push in the right direction, if you take a look at columns.render examples, it should clarify more.

    {
        "targets": 3,
        "data": "user_id",
        "render": function ( data, type, row, meta )
        {
            return "Data 1: " + row.data().user_id + ". Data 2: " + row.data().user_name ;
        }
    }
    

    Any further questions feel free to ask ^-^
    David

  • pettedemonpettedemon Posts: 38Questions: 6Answers: 0
    edited October 2019

    @David@Quantum , so I have to change all the column rendering?
    I have to change the method of
    "colums":[ "data": "ora_appuntamento", ]

  • David@QuantumDavid@Quantum Posts: 36Questions: 4Answers: 2
    "columns": [
         {
           "className":      'details-control',
           "orderable":      false,
           "data":           null,
           "defaultContent": '',
     
         },
     
         {
             "render": function ( data, type, row, meta )
             {
                  return "Data: " + row.data().column_1_name + " AND " + row.data().column_2_name;
             }
     
         },
         {
             "data": "numero_telefono",
     
         },
     
     ],`
    

    What we're doing in the second column here is grabbing the data for the whole row and formatting it into a string that will be put into the column.

  • pettedemonpettedemon Posts: 38Questions: 6Answers: 0
    edited October 2019

    Hi @David@Quantum
    If I do

    "columns": [
         {
           "className":      'details-control',
           "orderable":      false,
           "data":           null,
           "defaultContent": '',
      
         },
      
         {
             "render": function ( data, type, row, meta )
             {
                  return "Data: " + row.data().column_1_name + " AND " + row.data().column_2_name;
             }
      
         },
         {
             "data": "numero_telefono",
      
         },
      
     ],`
    

    I have no render

    if I do

             "columnDefs":[
             {
                "targets": 1,
                "data": {nome : "nome", cognomel : "cognome", codice_fiscale : "codice_fiscale"},
                "render": function ( data, type, full )
                {
                  return data.nome+' '+data.cognome+' '+data.codice_fiscale;
                }
            }
            ],
    
    
    
            "columns": [
                {
                    "className":      'details-control',
                    "orderable":      false,
                    "data":           null,
                    "defaultContent": '',
    
                },
    
                {
    
                },
    

    The data in second column is not searchable

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited October 2019

    Hi @pettedemon ,

    This example here should get you going, it's showing how to use columns.render. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • pettedemonpettedemon Posts: 38Questions: 6Answers: 0

    Hi @colin ,
    the render is fully working, I am server-side Datatables.
    the others column are searchable but the column with render is not

            "columns": [
                {
                    "className":      'details-control',
                    "orderable":      false,
                    "data":           null,
                    "defaultContent": '',
    
                },
    
                {
                   "data": null,
                    render: function(data, type, row, meta)
                      {
                          return row.nome+' '+row.cognome+' '+row.codice_fiscale;
                      },
    
                },
    
                {
                    "data": "ora_appuntamento",
    
                },
                {
                    "data": "numero_telefono",
    
                },
    

    in my server-side script I have the data by

        array('db' => 'codice_fiscale', 'dt' => 'codice_fiscale'),
        array('db' => 'nome', 'dt' => 'nome'),
        array('db' => 'cognome', 'dt' => 'cognome'),
    

    so all the columns are searchable by default but not with the render. I try your example and it is fully working

    and the data in json are present

    {"draw":0,"recordsTotal":6,"recordsFiltered":6,"data":
    [{"DT_RowId":"row_10","data_appuntamento":"2019-09-20","ora_appuntamento":"11:00:00","numero_telefono":"11","data_telefonata":"2019-10-24","ora_telefonata":"14:00:00","ora_max_telefonata":"19:59:00","verifica_cancellata":"1","codice_fiscale":"g43reger","nome":"Mario 4","cognome":"Rossi 4"}]}
    
  • pettedemonpettedemon Posts: 38Questions: 6Answers: 0

    Hi @colin ,
    if I set my column to null I have not search
    If I set

     {
                   "data": "codice_fiscale",
    
                    render: function(data, type, row, meta)
                      {
                          return row.nome+' '+row.cognome+' '+row.codice_fiscale;
                      },
    
    
                },
    

    I have only codice_fiscale available in the search
    So how can enable all the data searchable? codice_fiscale + nome + cognome

    thanks

  • David@QuantumDavid@Quantum Posts: 36Questions: 4Answers: 2

    @pettedemon , I assume that DataTables searches columns based on data rather than actual contents. If you wanted it to be searchable you'd have to chose which value you'd want it to search by and set "data": null to that value.

    Regards,
    David

  • pettedemonpettedemon Posts: 38Questions: 6Answers: 0

    Hi, @David@Quantum
    so if I want search all the value?
    in the example of @Colin I can search all the value
    thanks

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Yep, as David said, try setting data: null, that's set in my example.

  • pettedemonpettedemon Posts: 38Questions: 6Answers: 0

    HI @colin ,
    I try to set but it doesn't work

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    This thread about server side searching rendered columns hopefully will help:
    https://datatables.net/forums/discussion/comment/117363/#Comment_117363

    Basically it suggests using this:

    {
                  "data": "codice_fiscale",
     
                   render: function(data, type, row, meta)
                     {
                         return row.nome+' '+row.cognome+' '+row.codice_fiscale;
                     },
     
     
               },
    

    and having hidden columns for nome and cognome.

    Kevin

This discussion has been closed.