Uncaught TypeError: Cannot read property '...' of null(…)

Uncaught TypeError: Cannot read property '...' of null(…)

mesqueebmesqueeb Posts: 38Questions: 12Answers: 1

My datatables have worked for a very long time without any problems, but today I revisited my page to find that suddenly it doesn't properly read the JSON data anymore.

This is my page: http://jtc.ae/?page=s_page

You need to do launch_datatable(); in console to launch it.

Basically I create my tables with JSON data and configured them like this: "data":jsonData,

Then I format my columns like this:

        "columns": [
            { "data" : "post_title" },
            { "data" : "post_meta.price_input",
              "defaultContent" : "",
              "render" : function( data, type, full, meta ){
                    //Get the USD rate
                    var dol_rate = $("#dol_rate").val();
                    var curr = full.post_meta.price_input_currency;

This is where the bug occurs, it cannot recognise this full.post_meta.price_input_currency; anymore...

Any ideas?

This question has an accepted answers - jump to answer

Answers

  • mesqueebmesqueeb Posts: 38Questions: 12Answers: 1

    Since it didn't happen on page 2 apparently it has to do with json data that was loaded which had null as value inside full.post_meta.

    I had to delete those objects as the whole page was bugging because of that but, any way to prevent this from happening in the future?

  • allanallan Posts: 63,791Questions: 1Answers: 10,512 Site admin
    Answer ✓

    Hi,

    Since your code is trying to access a property of the full.post_meta object you would need to first check if it is null or not. That is in your columns.render code, so it isn't something that DataTables will do for you (it can't!).

    Allan

  • mesqueebmesqueeb Posts: 38Questions: 12Answers: 1

    Something like if(full.post_meta!=null){ ... } ?

  • allanallan Posts: 63,791Questions: 1Answers: 10,512 Site admin

    Looks fine to me.

This discussion has been closed.