filter()

filter()

DavidRecaDavidReca Posts: 3Questions: 1Answers: 0

Hi, I am using the following code to load a table:

function addRowDT(data) {
var tabla = $('#tbl_PedidosGraf').DataTable()

for (var i = 0; i < data.length; i++) {
    tabla.row.add([
        data[i].IdPedidosGraf,
        data[i].Grafica,
        data[i].Estado,
        data[i].FechaEnviado,
        data[i].Presupuesto,
        data[i].Cliente,
        data[i].Detalle,
        data[i].FechaPapel,
        data[i].PliegosCant,
        data[i].Formato,
        data[i].Sustrato,
        data[i].Impresion,
        data[i].Piezas,
        data[i].FechaImpreso,
        data[i].FechaRetirado,
        data[i].InfoAdicional
    ]).draw(false);
}

}

and I need to filter it by the vector [Estado], how can I do?
Tanks, David

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    One option is to use column().search(). If this doesn't help then please provide more info of how exactly you would like the table search to work.

    Kevin

  • DavidRecaDavidReca Posts: 3Questions: 1Answers: 0

    I manage to filter and show:

    var filtro = data
        .filter(function (result) {
            return result.Estado === 1;
        })
    
    console.log(filtro);
    

    preview:
    Array(3)
    0: {type: "_04_Entidades.PedidosGraf", IdPedidosGraf: 9, Grafica: "MDC Impresiones", Estado: 1, FechaEnviado: "20/11/2019 0:00:00", …}
    1: {__type: "_04_Entidades.PedidosGraf", IdPedidosGraf: 10, Grafica: "Sorgraf", Estado: 1, FechaEnviado: "25/11/2019 0:00:00", …}
    2: {__type: "_04_Entidades.PedidosGraf", IdPedidosGraf: 11, Grafica: "MDC Impresiones", Estado: 1, FechaEnviado: "20/11/2019 0:00:00", …}
    length: 3
    __proto
    : Array(0)

    I need to show that result in the table.
    tanks

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    The filter() API doesn't affect the table. Did you try tabla.column(2).search(1).draw()?

    Kevin

  • DavidRecaDavidReca Posts: 3Questions: 1Answers: 0

    Thanks Kevin, it worked!

This discussion has been closed.