<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: custom formatter + grouping + custom summary row === pain!</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/custom-formatter-grouping-custom-summary-row-pain</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/bugs/custom-formatter-grouping-custom-summary-row-pain/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>sprugman on custom formatter + grouping + custom summary row === pain!</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/custom-formatter-grouping-custom-summary-row-pain#p22313</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/custom-formatter-grouping-custom-summary-row-pain#p22313</guid>
        	        	<description><![CDATA[<p>If you use a custom column formatter with grouping &#38; a custom summaryType, it&#39;s very difficult to control how things render in the different situations. There are three different cases where you call the column formatter &#8212; for the row itself when ungrouped, for the group row when grouped, and again for the footer when grouped.</p>
<p>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?</p>
<pre>    /**
     * 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 == &#39;undefined&#39;) {
            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 : &#39;SUMMARY&#39;,
        GROUPING : &#39;GROUPING&#39;,
        FORMATTING : &#39;FORMATTING&#39;
    }
    
    /**
     * figure out what formatting mode we&#39;re in 
     * @todo    There&#39;s probably a better method than I&#39;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 == &#39;string&#39;) {
                if (options.rowId === &#39;&#39;) {
                    result = modes.SUMMARY;
                } else {
                    result = result = modes.GROUPING;
                }
            } else {
                result = modes.FORMATTING;
            }
        return result;
    };
</pre></p>
]]></description>
        	        	<pubDate>Thu, 03 Mar 2011 22:16:53 +0200</pubDate>
        </item>
</channel>
</rss>