[ 3 posts ]

Wilderness

  • Username: Wilderness
  • Joined: Wed Jun 13, 2012 4:52 pm
  • Posts: 2
  • Offline
  • Profile

YUI DataTable nested columns with JSON object/unknown keys.

Post Posted: Wed Jun 13, 2012 4:59 pm
+1-
I am pretty new to YUI and need some help.

I have a JSON response like this:

Code:
{
    "Results":[
        {
            "alpha":57.935,
            "beta:{
                "delta":2.975,
                "omega":1.431
            },
            "gamma":{
                "theta":"0.339",
                "lambda":"1.195"
            }
        },
        {
            "alpha":87,
            "beta":{
                "lambda":2.680,
                "kappa":0.714
            },
            "gamma":{
                "zeta":"0.288",
                "epsilon":"0.289"
            }
        }
    ]
}


I would like to have a datatable with nested columns where:
1) alpha, beta and gamma are parent columns.
2) beta and gamma each have two columns formed of the JSON key-value pair (e.g., delta => 2.975).
3) The number of rows, i.e., total key-value pairs, is dynamic.

Basically, something like this:

Code:
   ----------------------------------------------
    | alpha   |      beta      |       gamma     |
    ----------------------------------------------
    | 57.935  |  delta | 2.975 |   theta | 0.339 |
    ----------------------------------------------
    |         |  omega | 1.431 |  lambda | 1.195 |
    ----------------------------------------------
    | 87.435  | lambda | 2.680 |    zeta | 0.288 |
    ----------------------------------------------
    |         |  kappa | 0.714 | epsilon | 0.289 |
    ----------------------------------------------


I have been able to generate non-nested, simple JSON responses.

My problems:
1) I have the object for each JSON child ({theta:0.339}, etc.). Both child columns will need data from this same object. How do I use it without modifying it? Should I use the same 'keyName' for both child columns in myColumnDefs?
2) How to create more than one rows where alpha td is empty?

Any help will be appreciated !

Satyam

YUI Contributor

  • Username: Satyam
  • Joined: Tue Dec 09, 2008 12:34 am
  • Posts: 2016
  • Location: Sitges, Spain
  • GitHub: Satyam
  • Gists: Satyam
  • IRC: DevaSatyam
  • YUI Developer
  • Offline
  • Profile

Re: YUI DataTable nested columns with JSON object/unknown ke

Post Posted: Thu Jun 14, 2012 6:17 am
+0-
I wonder what would you do with a DataTable. No advanced feature of it would work with the format you want. Sorting would be out of the question, so would be cell editing or cell/row selection. Why bother with it at all?

If you really want, a solution might be to intercept the data when the DataSource gets it at one of the events listed at: http://developer.yahoo.com/yui/datasource/#events and transform the JSON object to another that maps to that format you are looking after.

Then, you can read: http://www.satyam.com.ar/yui/#grouping

Wilderness

  • Username: Wilderness
  • Joined: Wed Jun 13, 2012 4:52 pm
  • Posts: 2
  • Offline
  • Profile

Re: YUI DataTable nested columns with JSON object/unknown ke

Post Posted: Mon Jun 18, 2012 8:59 pm
+0-
Thanks, Satyam ! I figured it would be easier for me to use a supported format. I flattened my data into rows of fixed width (columns) and inserted keys for each field. That solved my problem. Thanks for your time !
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum