Template:dhtml table plus

    Table of contents
    No headers
    // This is a quick hack by Neil Weinstock, 2011, slightly extending the code from dhtml.table()
    //
    // For any column whose field name ends in "HTML" (case insensitive), the message text will be rendered as HTML
    // instead of plain text.  In your PageBus.publish(), you can either put in a string or XML literal, and it'll work the same.
    // Example:
    //
    // dhtml_table_plus("testChannel", [ { label:"text column", field:"text" }, { label:"html column", field:"someHTML" } ]);
    //
    // pagebus.publish("testChannel", { text:"this is some bold text", someHTML:"<b> BOLD TEXT </b>" }); // HTML passed as string
    // pagebus.publish("testChannel", { text:"this is an image", someHTML:<img src=(user.gravatar)/> }); // HTML passed as XML literal
    //
    
    var channel = $0 ?? $channel ?? "default";
    var columns = $1 ?? $columns ?? [ { "label":"you forgot to specify columns!", field:"null" } ];
    
    <html><head>
    <script type="text/javascript"> "
        $(function() {
            DekiWiki.subscribe("..json.emit(channel)..", null, n_dhtml_table_message_to_row,
                { id: "..json.emit(@id)..", columns: "..json.emit(columns).." });
        });
    " </script>;
    
    <script type="text/javascript"> "
        function n_dhtml_table_message_to_row(c, v, f) {
            var tbody = document.getElementById(f.id);
            var count = parseInt(tbody.getAttribute('count'));
            tbody.setAttribute('count', count + 1);
            var tr = document.createElement('tr');
            tr.setAttribute('class', (count & 1) ? 'feedroweven' : 'feedrowodd');
            for(var i in f.columns) {
                var column = f.columns[i];
                if(typeof(column) == 'object') {
                    var td = document.createElement('td');
                    if(DekiWiki.hasValue(v[column.field])) {
                        if (column.field.match(/html\\b/i)) td.innerHTML = v[column.field];
                        else                                td.innerText = v[column.field];
                    }
                    else td.innerHTML = '&nbsp;';
                    tr.appendChild(td);
                }
            }
            tbody.appendChild(tr);
        }
    " </script>;
    
    <style type="text/css"> "
        .feedtable {
            border:1px solid #999;
            line-height:1.5em;
            overflow:hidden;
            width:100%;
        }
        .feedtable th {
            background-color:#ddd;
            border-bottom:1px solid #999;
            font-size:14px;
        }
        .feedtable tr {
            background-color:#FFFFFF;
        }
        .feedtable tr.feedroweven td {
            background-color:#ededed;
        }
    " </style>;
    </head>
    <body>
    
        <table class="feedtable sortable">
            <thead><tr>
                foreach (var c in columns)
                    <th> c.label </th>;
            </tr></thead>;
            <tbody id=(@id) count="0"></tbody>;
        </table>;
        
    </body>;
    </html>;
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by