mData property with Dot special character

mData property with Dot special character

ssakthivssakthiv Posts: 3Questions: 0Answers: 0
edited September 2012 in DataTables 1.9
I am using mData in aoColumns to bind the datastore variables to my datatable columns. The problem i have is that the datastore properties pointed by mData have special characters '.' in them, hence datatable is considering it as nested object even though their value is plain string and i am getting "requested datasource name not found.." error.

Related Code:
[code]
"aoColumns" : [
{"sTitle": "Name", "mData": "name"},
{"sTitle": "Package", "mData": "name.package@v1"},
....
]
[/code]

Example data from server:
[code]
{
"aaData": [
{
"name": "Imperial Blue",
"name.package@v1": "Marketplace US"
},
{
"name": "Royal Blue",
"name.package@v1": "Marketplace US"
},
]
}
[/code]

I changed the behaviour of _fnGetObjectDataFn , _fnSetObjectDataFn methods to point to something other than '.' and it seems to work for me. May i know is there cleaner way to acheive this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    The way to do that is to use mRender as a function and something like `return data['name.package@v1'];` . There isn't a way to escape the dot in mData or mRender, so you need to mRender as a function.

    Allan
  • ssakthivssakthiv Posts: 3Questions: 0Answers: 0
    Hi Allan - Thanks for the prompt reply!!

    I tried as suggested, but getting "Requested unknown parameter '1' from the data source for row 0" error.

    Updated Code:
    [code]
    "aoColumns" : [
    {"sTitle": "Name", "mData": "name"},
    {"sTitle": "Package",
    "mRender": function ( data, type, full ) {
    return data['name.package@v1'];
    }
    }

    ....
    ]
    [/code]

    The output from the server is same as above. Am I missing something?
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hmm - good point - try this:

    [code]
    "aoColumns" : [
    {"sTitle": "Name", "mData": "name"},
    {"sTitle": "Package",
    "sDefaultContent": "",
    "mRender": function ( data, type, full ) {
    return full['name.package@v1'];
    }
    }

    ....
    ]
    [/code]

    Allan
  • ssakthivssakthiv Posts: 3Questions: 0Answers: 0
    Thanks a bunch....That's working like a charm
  • myahmed29myahmed29 Posts: 3Questions: 0Answers: 0
    Cool
This discussion has been closed.