julienrf/play-table — Issue #7: Adding parameters to column's header and body
Author: helioss1
Created: 2011-12-02 14:42:01+00:00
State: open

Hello,
as far as I know there isn't an option to add parameters to column's header (th tag in thead section of table), the only thing you can do, is to add parameters to td tags that corresponds to columns. I've made a small change, which now gives that possibility. I've replaced a code:

if (state.equals("head")) {
// Display the label
out.print("<th>");
if (args.containsKey("arg")) {
out.print(args.remove("arg"));
}
out.println("</th>");
} else {
// Display the content
printTag("td", args, out);
if (body != null) {
body.call();
}
out.println("</td>");
}

with

if (state.equals("head")) {
// Display the label
printTag("th", (Map<?, ?>)args.get("header"), out);
if (args.containsKey("arg")) {
out.print(args.remove("arg"));
}
out.println("</th>");
} else {
// Display the content
printTag("td", (Map<?, ?>)args.get("body"), out);
if (body != null) {
body.call();
}
out.println("</td>");
}

in _column method and a code:

for (Map.Entry<?, ?> entry : attributes.entrySet()) {
tag .append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
}

with:

if (attributes != null) {
for (Map.Entry<?, ?> entry : attributes.entrySet()) {
tag .append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
}
}

in printTag method. And now you can write header and body parameters in column tag inside template and define there an array of parameters for th and td tags respectively. i.e.

#{table list, as:'listElem' }
#{column 'Name', header:[class: 'myHeaderColumnClass', align: 'left'], body:[class: 'myBodyColumnClass', bgcolor: '#abcdef']}
${listElem.name}
#{/column}
#{/table}

Please take a look at this.