Resolve error on first row

Resolve error on first row

neomaltineneomaltine Posts: 5Questions: 2Answers: 0

Hi !

I'm parsing a JSON and the first object is an empty one. I'm getting some errors sometimes. How can avoid inserting the first object in the table ?

Thank you !

Answers

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2

    you can use sDefaultContent property for aoColumns.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    columns.defaultContent is the camel case name for that property which is the one listed in the documentation.

    Allan

  • neomaltineneomaltine Posts: 5Questions: 2Answers: 0
    edited December 2015

    It doesn't solve my problem.
    My json is an array of object, every object of that array contains sub-object but not the first object in the array. I'm returning data from the sub-object and I get an error on the first object which is empty and doesn't have a sub-object. How can I tell the library to ignore the first object in my json ?

    PS: This empty object makes me an empty line in my table which is not pleasant.

    I hope my explanation is clear :)

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2

    you should use mdata property for nested object.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    I don't really understand I'm afraid. Can you post your JSON please.

  • neomaltineneomaltine Posts: 5Questions: 2Answers: 0
    edited January 2016

    Thank you for your answers, here is the structure of my json :

    {
        "Data":[ {
            "AGENT_NOM": null, "AGENT2_NOM": null, "AGENT3_NOM": null, "GESTIONNAIRE_NOM": null, "CODE_SOCIETE": 0, "NO_ADRESSE": 0, "NOM_ABREGE": " "
        }
        ,
        {
            "AGENT_NOM": {
                "CODE_AGENT": "", "TITRE": "", "NOM_AGENT": "", "CODE_SERVICE": " "
            }
            ,
            "AGENT2_NOM":null,
            "AGENT3_NOM":null,
            "GESTIONNAIRE_NOM": {
                "CODE_AGENT": ""
            }
            ,
            "CODE_SOCIETE":0,
            "CRITERE_1":" ",
            "CRITERE_2":" ",
            "CRITERE_3":" ",
            "CRITERE_4":" ",
            "CRITERE_5":" ",
    
        }
        ],
        "Info": {
            "DataCountWithoutPaging": 0, "DataCount": 0, "Error": null
        }
    }
    

    Of course I deleted some stuff for privacy, as you can see the first object is emtpy. I want to bypass this first element. The second element contains informations but here I removed them because of privacy.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    I would suggest using ajax.dataSrc if you want to modify the data object that the server returns. Use something like:

    ajax: {
      url: ...,
      dataSrc: function ( json ) {
        json.Data.shift();
        return json.Data;
      }
    }
    

    i.e. remove the first element from the array and then return the remaining array.

    Allan

This discussion has been closed.