Using table.column( 4 ).data() .filter( function

Using table.column( 4 ).data() .filter( function

chessGuru64chessGuru64 Posts: 79Questions: 18Answers: 1

The click alerts "hi" but then nothing changes at all. I am doing server-side. I will PM project link if needed but I have a feeling I am missing something simple (or this is client-side only?)

 <a><p class="price" id="100">Under 100</p></a>

<script> 
 $(document).on('click','#100',function (){
     alert("hi");
var table = $('#example').DataTable();

var filteredData = table
    .column( 4 )
    .data()
    .filter( function ( value, index ) {
        return value > 100 ? true : false;
    } );
} );

$(document).ready(function() {
   var table=  $('#example').DataTable( {
       responsive: true,
        "processing": true,
        "serverSide": true,
        "searching": true,
        ajax: {
        url: 'server.php',
        type: 'POST',
        },
     columnDefs: [ 
         {  targets: -1,
         render: function (data, type, row, meta) {
            return '<button type="submit" class="add_btn btn btn-success btn-md active" data-id="' + meta.row + '"  id=" ' + meta.row + ' " data-toggle="modal" data-target="#insert_form"> <span class="fa fa-shopping-cart"></span> Add to Cart  </button>';
         }
         }
         ],

    })
} ); // end ready
</script>    

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947
    edited February 2019 Answer βœ“

    Your description doesn't explain what you are expecting. The filter() API is a client side method. The filteredData variable will contain the values found that are greater than 100. Checkout this example:
    http://live.datatables.net/suyirugi/1/edit

    What are you expecting/wanting to happen?

    Kevin

  • chessGuru64chessGuru64 Posts: 79Questions: 18Answers: 1

    Yes I would expect the code to only display options greater than 100. Instead nothing happens at all. Which makes sense because it’s client side only as I suspected

This discussion has been closed.