If you use a custom column formatter with grouping & a custom summaryType, it's very difficult to control how things render in the different situations. There are three different cases where you call the column formatter — for the row itself when ungrouped, for the group row when grouped, and again for the footer when grouped.
Theoretically, the footer and group row can have their own handlers, but as far as I can tell, those get mashed by the main column formatter. I wound up having to write something like the below. Am I missing something? Is there an easier way?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/**<br /> * Format the column.<br /> * Uses this.callCounter to count the number of times<br /> * the method is called, which is then used by getFormatterMode<br /> */<br /> function formatMyColumn(cellvalue, options, rowObject) {<br /> var result = cellvalue;<br /> if (typeof this.callCounter == 'undefined') {<br /> this.callCounter = 1;<br /> } else {<br /> this.callCounter++;<br /> }<br /> var mode = getFormatterMode(this.callCounter, cellvalue, options, rowObject);<br /> switch (mode) {<br /> case modes.SUMMARY :<br /> // format for summary<br /> break;<br /> case modes.GROUPING:<br /> // format for group row<br /> break;<br /> case modes.FORMATTING:<br /> // format for regular row<br /> break;<br /> }<br /> return result;<br /> }<br /> <br /><br /> /**<br /> * constants for the different modes that column formatters can be called in<br /> */<br /> var modes = {<br /> SUMMARY : 'SUMMARY',<br /> GROUPING : 'GROUPING',<br /> FORMATTING : 'FORMATTING'<br /> }<br /> <br /><br /> /**<br /> * figure out what formatting mode we're in<br /> * @todo There's probably a better method than I'm<br /> * using based on the values and types of the<br /> * second-fourth parameters.<br /> * In fact, options.rowId alone might be enough.<br /> * Need to do some more research.<br /> * @param {int} counter the number of times the formatter<br /> * function has been called for a given column<br /> * @param {Object} cellvalue cellvalue from the formatter call<br /> * @param {Object} options options from the formatter call<br /> * @param {Object} rowObject rowObject from the formatter call<br /> */<br /> var getFormatterMode = function(counter, cellvalue, options, rowObject) {<br /> var result;<br /> if (counter !== options.rowId) {<br /> if (typeof options.rowId == 'string') {<br /> if (options.rowId === '') {<br /> result = modes.SUMMARY;<br /> } else {<br /> result = result = modes.GROUPING;<br /> }<br /> } else {<br /> result = modes.FORMATTING;<br /> }<br /> return result;<br /> };<br /> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top