YUI 3.x Home -

YUI Library Examples: DataTable: Nested Column Headers

DataTable: Nested Column Headers

The DataTable widget supports nested column headers, which can be defined in the columnset definition using the children configuration.

Using Nested Column Headers

Use nested columns to visually group related column headers. The children attribute associates a parent column to its descendants. Note that only bottom-level columns will have data values. Any parent columns are there for presentation purposes only and do not hold any data values directly — therefore parent columns may have a label value but a key value is unnecessary.

  1. YUI().use("datatable-base", function (Y) {
  2. var nestedCols = [
  3. {
  4. label: "Train Schedule",
  5. children: [
  6. { key: "track" },
  7. {
  8. label: "Route",
  9. children: [
  10. {key:"from"},
  11. {key:"to"}
  12. ]
  13. }
  14. ]
  15. }
  16. ],
  17. data = [
  18. {track:"1", from:"Paris", to:"Amsterdam"},
  19. {track:"2", from:"Paris", to:"London"},
  20. {track:"3", from:"Paris", to:"Zurich"}
  21. ],
  22. table = new Y.DataTable.Base({
  23. columnset: nestedCols,
  24. recordset: data,
  25. summary: "Train schedule",
  26. caption: "Table with nested column headers"
  27. }).render("#nested");
  28.  
  29. ...
YUI().use("datatable-base", function (Y) {
    var nestedCols = [
        {
            label: "Train Schedule",
            children: [
                { key: "track" },
                {
                    label: "Route",
                    children: [
                        {key:"from"},
                        {key:"to"}
                    ]
                }
            ]
        }  
    ],
    data = [
        {track:"1", from:"Paris", to:"Amsterdam"},
        {track:"2", from:"Paris", to:"London"},
        {track:"3", from:"Paris", to:"Zurich"}
    ],
    table = new Y.DataTable.Base({
        columnset: nestedCols,
        recordset: data,
        summary: "Train schedule",
        caption: "Table with nested column headers"
    }).render("#nested");
 
    ...

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings