how can I filter the data I show via the ajax request?

0

I want to filter the data that returns the AJAX request to get only those that start with the letters vmi .

$('#datatable').DataTable({
  'dom': 'Bfrtip',
  'buttons': [{
      extend: 'excelHtml5',
      className: 'btn btn-primary',
      exportOptions: {
        columns: ':visible'
      }
    },
    {
      extend: 'pdfHtml5',
      className: 'btn btn-primary',
      exportOptions: {
        columns: ':visible'
      }
    },
    {
      extend: 'colvis',
      className: 'btn btn-primary',
      text: 'Columnas Visibles'
    }
    //'colvis'
  ],
  "columnDefs": [{
    "targets": -1,
    "visible": false
  }],
  "autoWidth": true,
  "ajax": {
    "url": "http://rev.zom.com.mx/extranete/WSs/Servicfios.svc/buscaRefer",

    "type": "POST",
    "contentType": "application/json; charset=utf-8",
    "data": function(d) {
      return data2;
    },
    "dataSrc": function(json) {
      console.log(json.data.length);
      for (var i = 0, ien = json.data.length; i < ien; i++) {



      }
      return json.data;

    }

  },

  "error": function(jqXmlHttpRequest, textStatus, errorThrown) {
    //alert("Datos Incorrectos"); //#coment
  }

});

The structure of the JSON that is returned is the following:

{
   "data":[
      [
         "-",
         "ALME18-00007",
         "5",
         "16/03/2018",
         "3843",
         "810",
         "8000045",
         "03/01/2018",
         "03/01/2018",
         "04/01/2018"
      ],
      [
         "-",
         "LCE18-00044",
         "6",
         "10/01/2018",
         "3843",
         "510",
         "8000077",
         "20/01/2018",
         "20/01/2018",
         "18/01/2018"
      ],
      [
         "-",
         "MAN18-00002",
         "4",
         "15/03/2018",
         "3235",
         "160",
         "8000040",
         "07/01/2018",
         "12/01/2018",
         "18/01/2018"
      ],
      [
         "-",
         "VMI18-00001",
         "1",
         "15/03/2018",
         "3843",
         "430",
         "8000068",
         "15/01/2018",
         "16/01/2018",
         "18/01/2018"
      ],
      [
         "-",
         "VMI18-00002",
         "3",
         "16/03/2018",
         "3843",
         "430",
         "8000070",
         "15/01/2018",
         "16/01/2018",
         "18/01/2018"
      ]
   ]
}
    
asked by emanuelle 07.05.2018 в 19:18
source

1 answer

2

Use the Array#filter method to filter by the predicate wanted:

...
"dataSrc": json => json.data.filter(arr => arr[1].startsWith('VMI')),
...
    
answered by 07.05.2018 / 19:27
source