How to join 2 columns in a datatables

0

What happens is that when I fill a table using the data tables plugin I do not want for example the paternal or maternal surname or the second name to appear in separate columns, but rather everything appears in a single column, How can I join the columns I need?

options = {
dom: "Bfrtip",
ajax: (data, callback, settings) => {
  this.servicioUsuarios.getUsuarios().subscribe(data => {
    callback({
      aaData: data
    })
  }, e => {
    this.notificaciones.notificacionError(e);
  });
},
columns: [
  { data: "id" },
  { data: "login" },
  { data: "nombre" },
  { data: "correo" },
  { data: "fechaAlta" },
  // { "defaultContent": "<button >Click!</button>"}
],
    
asked by Gonzalo Alberto 19.06.2017 в 23:14
source

2 answers

1

You can work it by position and make a concatenation.

Within the render you can do what you want and with the return print what you want to be displayed.

options = {
dom: "Bfrtip",
ajax: (data, callback, settings) => {
  this.servicioUsuarios.getUsuarios().subscribe(data => {
    callback({
      aaData: data
    })
  }, e => {
    this.notificaciones.notificacionError(e);
  });
},
columns: [
  { data: "id" },
  { data: "login" },
  { data: "nombre" },
  {"render":
        function ( data, type, row ) {
            return (row[3] + ' ' + row[4] + ' ' + row[5] + ' ' + row[6]);
            // donde, en teoría:
            // row[3] es 'primer_nombre'
            // row[4] es 'segundo_nombre'
            // row[5] es 'apellido_paterno'
            // row[6] es 'apellido_materno'
        }
  }, 
  { data: "correo" },
  { data: "fechaAlta" },
  // { "defaultContent": "Click!"}
],
    
answered by 20.06.2017 в 00:26
0

Concatenate the fields either in your datatables or in your sql statement

 options = {
    dom: "Bfrtip",
    ajax: (data, callback, settings) => {
      this.servicioUsuarios.getUsuarios().subscribe(data => {
        callback({
          aaData: data
        })
      }, e => {
        this.notificaciones.notificacionError(e);
      });
    },
    columns: [
      { data: "id" },
      { data: "login" },
      { data: "nombre" +" "+"segundo_mobre"+" "+"apellido_materno"+" "+"apellido_paterno"},
      { data: "correo" },
      { data: "fechaAlta" },
      // { "defaultContent": "<button >Click!</button>"}
    ],
    
answered by 20.06.2017 в 00:18