Hiding rows composed of null values

Hiding rows composed of null values

DanjmDanjm Posts: 4Questions: 3Answers: 0
edited March 2018 in Free community support

I have a table which retrieves JSON data using Ajax much like in this example https://datatables.net/examples/ajax/objects.html with the only difference being I had to include the following to account for the lack of a name for my list of objects. Below shows my code.

$(document).ready(function(){  
      var tables = $('#data2').DataTable({  
          "ajax" : {   
              url: 'gameseek.json',
              dataSrc: ''
        }, 
          "dom": '<"top"i>rt<"bottom">p<"clear">',
          "pagingType" : "simple",
          "columns"     :     [  
                {     "data"     :     "name"     },     
                {     "data"     :     "price"}  
           ]  
      });
});

The issue i'm having is that in this particular JSON file there's about 200 objects that have null as both fields, "name" and "price" meaning the first few pages of my table are just empty fields. Is there a way of hiding/not loading those rows? Hiding a row where "name" = null would have the same effect so if that's easier i'm happy to do that.
Thank you

This question has an accepted answers - jump to answer

Answers

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

    The best place to do this is to adjust your server's DB query to get only those rows with values for name and price. Syntax is based on your DB.

    However if you can't do that then I suggest using the ajax.dataSrc function option to loop through the data and keep only those rows you want. The third example in the doc show how to use it as a function.

    Kevin

This discussion has been closed.