<?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: TUTO advanced formatter</title>
	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter</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/tuto-advanced-formatter/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>bouks on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29164</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29164</guid>
        	        	<description><![CDATA[<p>Ho. Ho.</p>
<p>That was just a joke about history and politics.</p>
</p>
<p>Good luck with your project.</p>
]]></description>
        	        	<pubDate>Fri, 12 Jul 2013 16:22:53 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29163</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29163</guid>
        	        	<description><![CDATA[<p>Sorry, but <span style="text-decoration: underline;">it&#39;s not what I would recommend</span> you. Could you post more full code which you use: <em>at least one line of input data</em> is required. You should post the <strong>colModel</strong> definition too where you use&#160;<span style="font-size: 14px;"><strong>isBirth</strong> and <strong>ageFormatter</strong>&#160;formatter. The better to post small demo and I would modify the demo to the way which I would prefer.</span></p>
<p><span style="font-size: 14px;">I wrote initially to your post just to help you to find better was of usage some jqGrid features. I did it in a pause in my main job. I don&#39;t wanted to start long discussion because of a few time now. I have to provide working solution for the project on which I&#39;m working now next week (it has no relation to jqGrid and to web defelopment at all like the most of my main job). Only because of few time I wanted to stop the discussion.</span></p>
<p><span style="font-size: 14px;">German is foreign language for me like English. So we can&#39;t speak about any "complicated relations between frenchs and germans". By the way I though about some problem only at the time of leaving in Russia. If I visit my friends in France I seen some such problems too, but I never seen any such problem during my living in Germany (last 20 years). German&#160;people are really opened to to all foreigner.</span></p>
]]></description>
        	        	<pubDate>Fri, 12 Jul 2013 16:00:12 +0300</pubDate>
        </item>
        <item>
        	<title>bouks on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29162</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29162</guid>
        	        	<description><![CDATA[<p>Okay Oleg.</p>
<p>I understand you don&#39;t want to continue this discussion.</p>
<p>Maybe it&#39;s a misunderstood of english foreign langage peoples, maybe it&#39;s the view of theory against the practice one, maybe it&#39;s due to complicated relations between frenchs and germans ( 😀 )&#160;...</p>
<p>Just permit me to post this answer, to not confuse readers and really make them an opinion (i did this for "tuto" purpose) on these different povs. Also I made a mistake in my if statement, i have to correct it for people, so if they copy/paste they have expected result.</p>
<p>Note to jqGrid purists ( 😀 ) : the goal is not using formatter to change cell style. The goal is to do smarter code on some cases.</p>
</p>
<p>The following, i recommend (this is for a formatter for an age column) :</p>
</p>
<pre>function isBirth(cellValue, options, rowObject) {
    d2 = new Date();
    d1 = new Date(rowObject.birth);
    var diff = d2.getTime() - d1.getTime();
    if (d1.getMonth() === d2.getMonth() &#38;&#38; d1.getDate() === d2.getDate()) {
        options.colModel.classes = &#39;annniversary-background-color&#39;;
    }
    return Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));
}
</pre>
</p>
<p>The following is the way you recommend. See i really try to do like you recommend but i&#39;m not sure such dependencies are really good...</p>
</p>
<pre>function ageFormatter(cellValue, options, rowObject) {
    d2 = new Date();
    d1 = new Date(rowObject.birth);
    var diff = d2.getTime() - d1.getTime();
    if (d1.getMonth() === d2.getMonth() &#38;&#38; d1.getDate() === d2.getDate()) {
        rowObject.myConfigVar.Anniversary = &#39;lalala&#39;;
    }
    return Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));
}

function ageCellattr(rowId, value, rowObject, colModel, arrData) {
    if (rowObject.myConfigVar.Anniversary === &#39;lalala&#39;) {
	return &#39;class="annniversary-background-color"&#39;;
    }
}
</pre>
</p>
<p>Unless you have better implementation to tell me.</p></p>
]]></description>
        	        	<pubDate>Fri, 12 Jul 2013 14:46:45 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29160</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29160</guid>
        	        	<description><![CDATA[<p>Sorr, but I don&#39;t understand what you don&#39;t understand.</p>
<p>If you need to change <strong>the style</strong> of the cell like in isDebt example then you should use <strong>cellattr</strong>. The main advantage is that <em>you can still use some <a href="/jqgridwiki/doku.php?id=wiki:predefined_formatter#predefined_format_types" target="_blank">predefined formatter</a> for the column</em>. For example you can use <strong>formatter: "number"</strong> or <strong>formatter: "date"</strong>. So the number can be displayed with thousand separator and decimal separator defined in locale. You still can access to the whole data of rows using third parameter of <strong>cellattr&#160;</strong>(rawObject).</p>
<p>If you need to change the content of cell (the content of &#60;td&#62;) then you should use custom formatter.</p>
<p>If you need to include new column which data not exist in the server response, but which can be calculated from content of other columns (like sum from some other columns or like Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25)) expression) you should better do this inside of <strong>beforeProcessing</strong> callback. In the way you set really only the value (like in <strong>isBirth</strong>). You can combime the approatch with <strong>loadonce: true</strong> or <em>use some predefined formatter for the column</em>.</p>
<p>I don&#39;t want to cotinue the discussion further. I wrote above my opinion about the best way usage of some jqGrid features.</p>
<p>Regards<br />Oleg&#160;</p></p>
]]></description>
        	        	<pubDate>Fri, 12 Jul 2013 10:06:00 +0300</pubDate>
        </item>
        <item>
        	<title>bouks on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29157</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29157</guid>
        	        	<description><![CDATA[<p>Sure I&#39;ll use templating, Oleg.</p>
<p>For the cellattr I really don&#39;t understand.</p>
</p>
<p>- formatter can change value but celattr can&#39;t</p>
<p>- formatter can change css (by class) as well as cellattr. (also defining class is really better than style)</p>
<p>- The second argument of formatter&#39;s function (containing gid) is not in cellattr&#39;s arguments. You can&#39;t access outside the row.</p>
</p>
<p>So i&#39;ll be curious to see how you write my birth function, please.</p>
]]></description>
        	        	<pubDate>Fri, 12 Jul 2013 05:11:49 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29149</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29149</guid>
        	        	<description><![CDATA[<p>Sorry, but I can&#39;t full follow your last arguments. You don&#39;t need to define can define cellattr or rowattr as anonymous function. You can use function statement or save anonymous function to variable and use the name of function/variable as the value of cellattr or rowattr. In other words you can do almost the same what you do with <strong>formatter</strong> property, but use <strong>cellattr</strong> instead. The implementation of <strong>cellattr</strong>&#160;will be a little other.</p>
<p>The callbacks <strong>cellattr</strong>&#160;and <strong>rowattr</strong> have optional parameters which you can use to access the content of other items of the row (like <strong>rowObject</strong> option of custom formatter). So all warks exactly like with costom formatter.</p>
<p>If you have long defintions for columns in <strong>colModel</strong> I would recommend you to use column templates. See <a href="http://stackoverflow.com/a/6047856/315935" target="_blank">the answer</a> for more information. The feature can dramatically reduce the size of the <strong>colModel</strong>, makes your code more readable and easy to maintain because you will have less duplicates of the code.</p>
<p>Best regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Thu, 11 Jul 2013 15:49:44 +0300</pubDate>
        </item>
        <item>
        	<title>bouks on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29148</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29148</guid>
        	        	<description><![CDATA[<p>I understand your argument.</p>
</p>
<p>Why have i been choosing this way :</p>
<p>- i don&#39;t want to multiply functions if not necessary.</p>
<p>With isBirth example function using formatter, i don&#39;t have to write 3 functions for doing what i&#39;m doing.</p>
<p>- i want to minimize colmodel definition (which is very long and boring 🙂 )&#160;</p>
<p>- i want to have access to the whole grid (set alert or message on toolbar for example) and elements</p>
<p>With isBirth example&#160;function using formatter, i have quick access to another cell to get its value.</p>
</p>
<p>So i use it like a cellInit which i think is not existing.</p>
</p>
<p>Maybe you have better example for me ?</p>
</p>
<p>What about "This would be awesome if this forum have some kind of tuto and script &#39;forum&#39;. With code formatting plugin please."</p>
<p>It would be great to complete the documentation.</p>
]]></description>
        	        	<pubDate>Thu, 11 Jul 2013 14:45:09 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29147</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29147</guid>
        	        	<description><![CDATA[<p>I think it&#39;s not good to use custom formatter to change CSS of the cell. jqGrid provide <strong>cellattr</strong> for the purpose. One can use additionally <strong>rowattr</strong> to set CSS on the whole row of grid instead of changing the style of the cell only. It allows to use some formatter (like formatter: "currency") to format <em>the content</em> of the cell and use <strong>cellattr</strong>&#160;or <strong>rowattr</strong>&#160;to change CSS style or other attributes (like custom <strong>title</strong>) of the cell or of the row.</p>
<p>See <a href="http://stackoverflow.com/a/9664440/315935" target="_blank">the answer</a> or&#160;<a href="http://stackoverflow.com/a/12180842/315935" target="_blank">the answer</a>&#160;for code examples of usage <strong>cellattr</strong> and <a href="http://stackoverflow.com/a/10531680/315935" target="_blank">this one</a> for the corresponding code examples.</p>
<p>Best regards<br />Oleg&#160;</p>
]]></description>
        	        	<pubDate>Thu, 11 Jul 2013 14:04:17 +0300</pubDate>
        </item>
        <item>
        	<title>bouks on TUTO advanced formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29146</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/tuto-advanced-formatter#p29146</guid>
        	        	<description><![CDATA[<p>You can do much more than format the value with the formatter option as see in the doc. Let see with simple examples.</p>
<p>You want to change the css (color, font things...) of a cell in regard of his value.</p>
<p>"i want to have a red color for this cell if my client owe me money".</p>
</p>
<pre>{
    label: &#39;balance&#39;, name: &#39;balance&#39;, index: &#39;balance&#39;,
    formatter: isDebt
}
</pre>
<pre>function isDebt(cellValue, options, rowObject) {
    if (cellValue !== Math.abs(cellValue)){
       options.colModel.classes = &#39;red-color&#39;;
    }
}
</pre>
</p>
<p>You want to change the css (color, font things...) of a cell in regard of another cell value.</p>
<p>Example "i want to have the background color of the age cell if this is the user anniversary (that is in column birth)"</p>
<pre>function isBirth(cellValue, options, rowObject) {
    d2 = new Date();
    d1 = new Date(rowObject.birth);
    var diff = d2.getTime() - d1.getTime();
    if (d1.toDateString() === d2.toDateString()) {
        options.colModel.classes = &#39;annniversary-background-color&#39;;
    }
    return Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));
}
</pre>
</p>
<p>You have access to the whole row, values and properties.</p>
</p>
<p>You want more ? There it is.</p>
</p>
<p>$(&#39;#&#39; + options.gid).jqGrid...</p>
</p>
<p>Enjoy.</p>
</p>
<p>PS: This would be awesome if this forum have some kind of tuto and script &#39;forum&#39;. With code formatting plugin please. 🙂</p>
]]></description>
        	        	<pubDate>Thu, 11 Jul 2013 00:24:20 +0300</pubDate>
        </item>
</channel>
</rss>