<?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: allow to use strings as values of cellattr and rowattr</title>
	<link>http://www.trirand.com/blog/?page_id=393/feature-request/allow-to-use-strings-as-values-of-cellattr-and-rowattr</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/feature-request/allow-to-use-strings-as-values-of-cellattr-and-rowattr/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>OlegK on allow to use strings as values of cellattr and rowattr</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/allow-to-use-strings-as-values-of-cellattr-and-rowattr#p31359</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/allow-to-use-strings-as-values-of-cellattr-and-rowattr#p31359</guid>
        	        	<description><![CDATA[<p>Hello Tony,</p>
<p>I suggest to allow to use string values forÂ <strong>cellattr</strong> andÂ <strong>rowattr</strong> in the same way like one can now to use strings as the value for <strong>template</strong> (see <a href="https://github.com/tonytomov/jqGrid/pull/631" target="_blank">the pull request</a>):</p>
<div class="sfcode">
<pre class="brush-javascript syntax">$.extend($.jgrid,{
    cellattr: {
        someCellAttrValue: function (rowId, val, rawObject) {
            ...
        }
    },
    rowattr: {
        someRowAttrValue: function (rd) {
            ...
        }
    }
});</pre></div><p>The corresponding changes in jqGrid code are very easy. To allow the usage string values forÂ <strong>cellattr</strong>Â one need to change <a href="https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L1086" target="_blank">the line</a></p>
<div class="sfcode">
<pre class="brush-javascript syntax">var cm = ts.p.colModel[pos],</pre></div><p>to</p>
<div class="sfcode">
<pre class="brush-javascript syntax">var cm = ts.p.colModel[pos], cellAttrFunc,</pre></div><p>and <a href="https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L1092-L1094" target="_blank">the lines</a></p>
<div class="sfcode">
<pre class="brush-javascript syntax">} <span class="k">else</span> <span class="k">if</span> (cm.cellattr <span class="o">&#38;&#38;</span> $.isFunction(cm.cellattr))
{
    celp <span class="o">=</span> cm.cellattr.<span class="nf">call</span>(ts, rowId, tv, rawObject, cm, rdata);</pre></div><p>to the following</p>
<div class="sfcode">
<pre class="brush-javascript syntax">} else if ($.isFunction(cm.cellattr) &#124;&#124; (typeof cm.cellattr === "string" &#38;&#38; $.jgrid.cellattr != null &#38;&#38; $.isFunction($.jgrid.cellattr[cm.cellattr]))) {
    cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];
    celp = cellAttrFunc.call(ts, rowId, tv, rawObject, cm, rdata);</pre></div><p>In the same way to allows the usage of string as the value of <strong>rowattr</strong> one need to change <a href="https://github.com/tonytomov/jqGrid/blob/v4.6.0/js/grid.base.js#L1219" target="_blank">the line</a>Â </p>
<div class="sfcode">
<pre class="brush-javascript syntax">rowAttrObj <span class="o">=</span> $.isFunction(ts.p.rowattr) <span class="o">?</span> ts.p.rowattr.<span class="nf">call</span>(ts, rd, cur, id) <span class="o">:</span>{};</pre></div><p>to the lines</p>
<div class="sfcode">
<pre class="brush-javascript syntax">rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :
    (typeof ts.p.rowattr === "string" &#38;&#38; $.jgrid.rowattr != null &#38;&#38; $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ?
        $.jgrid.rowattr[ts.p.rowattr].call(ts, rd, cur, id) : {});</pre></div><p>One can modify the code more to allow to use <strong>cellattr</strong> andÂ <strong>rowattr</strong> as comma-separated string with the values <strong>$.jgrid.cellattr</strong> and <strong>$.jgrid.rowattr</strong>. In the way one could allow applying of multiple callback functionsÂ (the stack) at once. In general such extension could have sense for <strong>formatter</strong>Â andÂ <strong>template</strong> values too.</p>
<p><a href="http://www.ok-soft-gmbh.com/jqGrid/cellattrAndRowAttrAsString.htm" target="_blank">The demo</a>Â demonstrates the changes working.</p>
<p>Best regards<br />
Oleg</p>
]]></description>
        	        	<pubDate>Sun, 09 Nov 2014 15:02:42 +0200</pubDate>
        </item>
</channel>
</rss>