Join three fields in one column

Join three fields in one column

rsarubbirsarubbi Posts: 2Questions: 1Answers: 0
edited April 20 in Free community support

I have the following code.

$(document).ready(function() {
    $('#viewdata_id').DataTable({
        dom: 'lBfrtip',
        buttons: ['excelHtml5', 'pdfHtml5', 'csvHtml5', 'print'],
        "language":
        {
            "sProcessing":     "Procesando...",
            "sLengthMenu":     "Mostrar _MENU_ registros",
            "sZeroRecords":    "No se encontraron resultados",
            "sEmptyTable":     "Ningún dato disponible en esta tabla",
            "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
            "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
            "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
            "sInfoPostFix":    "",
            "sSearch":         "Buscar:",
            "sUrl":            "",
            "sInfoThousands":  ",",
            "sLoadingRecords": "Cargando...",
            "oPaginate":
            {
                "sFirst":    "Primero",
                "sLast":     "Último",
                "sNext":     "Siguiente",
                "sPrevious": "Anterior"
            },
            "oAria":
            {
                "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
                "sSortDescending": ": Activar para ordenar la columna de manera descendente"
            }
        },
        "lengthMenu": [10,25],
        "pagingType": "full_numbers",
        "searching": true,
        "processing": true,
        "serverSide": true,
        "ajax":{
            url: URL_VIEW_DATA_INVOICE,
            type: "GET",
            headers: {"Authorization": "Bearer " + localStorage["jwt"]},
        },
        "columns": [
            { "data": "document_type" },
            { "data": "point_of_sale_number" },
            { "data": "invoice_number" },
            { "data": "invoice_date" },
            { "data": "sender_business_name" },
            { "data": "sender_tax_code" },
            { "data": "amount_before_tax" },
            { "data": "amount_vat"},
            { "data": "amount_total"},
            { "data": "_file_id"}
        ],
        "columnDefs":
        [
          {
             "targets": 9,
             "data": "_file_id",
             "render": function ( data, type, row, meta )
             {
                 return '<a href=' + URL_VIEW_DATA_DOWNLOAD + '/' + data + '>Descargar</a>';
             }
          },
          { "sClass": "numericCol", "targets": 7 },
          { "sClass": "numericCol", "targets": 8 },
          { "sClass": "numericCol", "targets": 9 }
      ]
     });

  });

I need to join this two fields in one column called Invoice Number

       { "data": "point_of_sale_number" },
            { "data": "invoice_number" },

For intance my web service return 0002 12345678.

The is to put both en the same column.

I red the documentation but I cannot understand how to to it.

I try differents wa but I cannot do it.

Regards, Richard

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 46,189Questions: 1Answers: 6,410 Site admin

    The columns.render option is the way to do this. The full documentation for it is here - if you would like any specific part of it clarified, please just let me know.

    Allan

  • rsarubbirsarubbi Posts: 2Questions: 1Answers: 0

    In the documentation you sent me, I find the following:

    {
    "product": "Toy car",
    "creator": {
    "firstName": "Fiona",
    "lastName": "White"
    },
    "created": "2015-11-01",
    "price": 19.99,
    "cost": 12.53
    }

    In my understanding "creator" is an object that has two members, not only a simple string.

    Is there a way to join two fields that are, as in my case, a single string or a single number?

    For instance, can I render "price" and "cost" in the same column od the datatable?.

    Thanks a lot from Buenos Aires.

    Richard

  • allanallan Posts: 46,189Questions: 1Answers: 6,410 Site admin

    In your case you would use:

    render: function ( data, type, row ) {
      return row.price +' '+ row.cost;
    }
    

    Allan

Sign In or Register to comment.