Forum
22:16
08/10/2010
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?
/** * Format the column. * Uses this.callCounter to count the number of times * the method is called, which is then used by getFormatterMode */ function formatMyColumn(cellvalue, options, rowObject) { var result = cellvalue; if (typeof this.callCounter == 'undefined') { this.callCounter = 1; } else { this.callCounter++; } var mode = getFormatterMode(this.callCounter, cellvalue, options, rowObject); switch (mode) { case modes.SUMMARY : // format for summary break; case modes.GROUPING: // format for group row break; case modes.FORMATTING: // format for regular row break; } return result; } /** * constants for the different modes that column formatters can be called in */ var modes = { SUMMARY : 'SUMMARY', GROUPING : 'GROUPING', FORMATTING : 'FORMATTING' } /** * figure out what formatting mode we're in * @todo There's probably a better method than I'm * using based on the values and types of the * second-fourth parameters. * In fact, options.rowId alone might be enough. * Need to do some more research. * @param {int} counter the number of times the formatter * function has been called for a given column * @param {Object} cellvalue cellvalue from the formatter call * @param {Object} options options from the formatter call * @param {Object} rowObject rowObject from the formatter call */ var getFormatterMode = function(counter, cellvalue, options, rowObject) { var result; if (counter !== options.rowId) { if (typeof options.rowId == 'string') { if (options.rowId === '') { result = modes.SUMMARY; } else { result = result = modes.GROUPING; } } else { result = modes.FORMATTING; } return result; };
Most Users Ever Online: 715
Currently Online:
33 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66