Label in Column

Label in Column

Cro22Cro22 Posts: 1Questions: 1Answers: 0
edited December 2018 in Free community support

Hello!
I am new using DataTable and I have a small problem.
In a column I must show a label depending on its value.
I managed to show the Label but only the first value

Alta: Yes! It's Blue!
Baja: Er... It should be red...
"aoColumns": [{
"targets": 0,
"searchable": false,
"orderable": false,
"className": "dt-body-center"
{
"data": "movimiento_fecha_hora"
},
{
"data": function(data, dataIndex) {
if (data.prioridad_expediente_id = 1) {
return '<label class="label label-primary">' + data.prioridad_expediente_descripcion;
}
if (data.prioridad_expediente_id = 2) {
return '<label class="label label-success">' + data.prioridad_expediente_descripcion;
}
if (data.prioridad_expediente_id = 3) {
return '<label class="label label-danger">' + data.prioridad_expediente_descripcion;
}
}
}],
And ... how do I show the date in dd/mm/yyyy format? Without the time

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    how do I show the date in dd/mm/yyyy format? Without the time

    One option is to manipulate the date using orthogonal data like the 'Transforming data` section here:
    https://datatables.net/manual/data/renderers#Functions

    For example:

            render: function (data, type, row) {
              var date = new Date(data);
              return (date.getMonth()+1) + '/' + date.getDate() + '/' +  date.getFullYear();
            }
    

    Or you could use moment.js to return the formatted date.

    show a label depending on its value.

    You have incorrect syntax in your if statements: if (data.prioridad_expediente_id = 1) {

    You need to use either == or ===, for example:

    `if (data.prioridad_expediente_id === 1) {
    

    Kevin

This discussion has been closed.