Json sub-array problem

Json sub-array problem

merihmerih Posts: 24Questions: 0Answers: 0
edited April 2012 in General
Hello,

In this example blow , "propertyAdaptor" length can change in different examples and It depends on the json data..
So Is it possible to get length of the data and write it in for loop?
like this? :)
propertySize = oObj.aData.propertyAdaptor.length;
for(i=0; i

Replies

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    > So Is it possible to get length of the data and write it in for loop?

    Absolutely - what you want to do here is use mDataProp as a function. Handily enough I wrote a blog post about that subject yesterday: http://datatables.net/blog/Orthogonal_data :-). You aren't dealing with orthogonal data here, but the pre-formatting of your data with mDataProp as a function does apply.

    Allan
  • merihmerih Posts: 24Questions: 0Answers: 0
    Hi allan,

    Thank you for your quick response..
    I checked the blog that you post but It looks that function uses for the pre-formatting the data.. That's not exactly what I need. I don't want to format data.
    The problem is; The column length and mDataProp length should be the same. Otherwise property datas and columns don't match and I get error.. For example if there is 3 column there should be three mDataProp as well.

    But in my situation, I know that "propertyAdaptor" sub array length can change...
    So the column length also can change.
    I create coumns dynamically using java but I should do the same thing for propertyAdaptor.

    For Example;
    there is 3 property in "propertyAdaptor" sub array,
    [code]
    [
    {"systemId":"86210","endOfUse":"","startOfUse":"","dateModified":"26/03/2012 04:59","identity":"P600540","name":"xxxx","propertyAdaptor":[{"name":"Description","value":"test test test test test"},{"name":"Group","value":"B"},{"name":"Point","value":"1411"}]},
    {"systemId":"86211","endOfUse":"","startOfUse":"","dateModified":"26/03/2012 04:59","identity":"P600550","name":"yyyy","propertyAdaptor":[{"name":"Description","value":"test test test test test"},{"name":"Group","value":"C"},{"name":"Point","value":"979"}]},
    {"systemId":"86212","endOfUse":"","startOfUse":"","dateModified":"26/03/2012 04:59","identity":"P600560","name":"zzzz","propertyAdaptor":[{"name":"Description","value":"test test test test test"},{"name":"Group","value":"A3"},{"name":"Point","value":"10733"}]}
    ]
    [/code]
    so the result should be;
    { "mDataProp": "propertyAdaptor.0.value"},
    { "mDataProp": "propertyAdaptor.1.value"},
    { "mDataProp": "propertyAdaptor.2.value"},

    But at this example below there is 2 property in "propertyAdaptor" sub array

    [code]
    [
    {"systemId":"86210","endOfUse":"","startOfUse":"","dateModified":"26/03/2012 04:59","identity":"P600540","name":"xxxx","propertyAdaptor":[{"name":"Prices","value":"200"},{"name":"Test","value":"A"}]},
    {"systemId":"86211","endOfUse":"","startOfUse":"","dateModified":"26/03/2012 04:59","identity":"P600550","name":"yyyy","propertyAdaptor":[{"name":"Prices","value":"200"},{"name":"Test","value":"B"}]},
    {"systemId":"86212","endOfUse":"","startOfUse":"","dateModified":"26/03/2012 04:59","identity":"P600560","name":"zzzz","propertyAdaptor":[{"name":"Prices","value":"200"},{"name":"Test","value":"C"}]}
    ]
    [/code]
    so the result should be;
    { "mDataProp": "propertyAdaptor.0.value"},
    { "mDataProp": "propertyAdaptor.1.value"},


    I need something like below;

    propertySize = oObj.aData.propertyAdaptor.length;
    for(i=0; i
  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Try:

    [code]
    "mDataProp": function (data, action, val) {
    if ( action === set ) {
    data.propertyAdaptor = val;
    data.propertyAdaptor_formatted = "";

    for(i=0; i
This discussion has been closed.