how to show previous and next row in search

how to show previous and next row in search

agg9505agg9505 Posts: 11Questions: 5Answers: 0

I have a column wich is a number so if the value is 1,2,3,4,5,6,74,8,9 in each row, if I search the number 5, y want to display the previous row and the next one like 4,5,6.

Is this posible? how?

I have two datatables in the page so I have to specify the search for one them.

var InitTable = function (ds, c, table, Csettings, buttons, order) {
    if (buttons == 'undefined') {
      buttons = [];
    }
    if (Csettings == 'undefined') {
      Csettings = [];
    }
    if (order == 'undefined') {
      order = 'asc';
    }
    table.DataTable({
      //"scrollY": 400,
      //"scrollCollapse": false,
      "bFilter": true,
      "destroy": true,
      "data": ds,
      "columns": c,
      "language": {
        "aria": {
          "sortAscending": ": Orden Ascendente",
          "sortDescending": ": Orden Descendente"
        },
        "emptyTable": "No hay datos para mostrar",
        "info": "Mostrando _START_ hasta _END_ de _TOTAL_ registros",
        "infoEmpty": "No se encontraron registros",
        "infoFiltered": "(Filtrado desde _MAX_ registros totales)",
        "lengthMenu": "_MENU_ Registros",
        "search": "Buscar:",
        "zeroRecords": "No se encontraron registros",
        "paginate": {
          "next": "Siguiente",
          "previous": "Anterior"
        }
      },
      "buttons": buttons,
      "responsive":true,
      "order": [
        [0, order]
      ],
      "lengthMenu": [
        [5, 10, 15, 20, -1],
        [5, 10, 15, 20, "Todos"] // change per page values here
      ],
      "pageLength": 5,
      "columnDefs": Csettings,
      fixedColumns: false
    });
  };

thanks....

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945
    Answer ✓

    There is nothing built-in to do this. You would need to create a custom search function. How that function is built is largely based on your data and requirements. Here is a simplistic example based on your above example of data (1,2....,8,9).
    http://live.datatables.net/zilepuge/1/edit

    Basically the function gets an array of the numbers column in sorted order. Then finds the position in the array of the value and gets the value to either side. Then builds a regex search of val1|val2|val3 and searches the column.

    Not much error checking and there may be a more efficient way to determine the rows to either side of the searched data. Maybe this will give you some ideas of how to approach your problem.

    Kevin

This discussion has been closed.