JSFiddle - React, Tailwind, and code Playground

by geocolumbus

HTML

<body class="yui3-skin-sam">
    <div id="myDataTable"></div> <pre id="csv"></pre>

</body>

JavaScript

YUI().use('node', 'model-list', 'model', 'datatable', function (Y) {

    var tableNode = Y.one('#myDataTable'),
        data = [{
            last: "Campbell",
            first: "George",
            id: "ga-3475",
            desc: "I said \"Hello, there.\"",
            price: "$6.99",
            cost: "$5.99"
        }, {
            last: "Campbell",
            first: "George",
            id: "sp-9980",
            desc: "sprocket",
            price: "$3.75",
            cost: "$3.25"
        }, {
            last: "Campbell",
            first: "George",
            id: "wi-0650",
            desc: "widget,green",
            price: "$4.25",
            cost: "$3.75"
        }],
        myDataTable = new Y.DataTable({
            columns: ["id", {
                label: "Name",
                children: [{
                    key: "last"
                }, {
                    key: "first"
                }]
            }, "desc", "price", "cost"],
            data: data,

            // Optionally configure your table with a caption
            caption: "My first DataTable!",

            // and/or a summary (table attribute)
            summary: "Example DataTable showing basic instantiation configuration"
        });

    myDataTable.render(tableNode);
    Y.one("#csv").setHTML(convertToCSV(myDataTable));

    // Function to convert a DataTable with zero or one nested columns to CSV
    function convertToCSV(myDataTable) {
        var col,
        colIndex = 0,
            colKey,
            rowString,
            ret,
            cell,
            headerString = "";

        while (col = myDataTable.getColumn(colIndex++)) {
            if (col.children == null) {
                headerString += '"' + col.key + '",';
            } else {
                Y.Array.each(col.children, function (child) {
                    headerString += '"' + child.key + '",';
                });
            }
        }
        ret = headerString.replace(/,$/,...