<?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: More on periods/colons in IDs</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids</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/help/more-on-periodscolons-in-ids/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>rodk on More on periods/colons in IDs</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15969</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15969</guid>
        	        	<description><![CDATA[<p>Tony,</p>
<p>Thanks.&#160; Didn&#39;t know about jqID.&#160; I&#39;m going to play around with it a bit to see if I can determine the best way to handle this.&#160; It&#39;s probable that each solution will have places where one works better than the others.</p>
]]></description>
        	        	<pubDate>Thu, 25 Mar 2010 21:25:48 +0200</pubDate>
        </item>
        <item>
        	<title>tony on More on periods/colons in IDs</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15935</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15935</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Thank you for the investigations and recommendations.</p>
<p>I think that there will be a long disscusion on should we have id or not, should we have on every DB table</p>
<p>uniquie id or not. All these are up to developer and for the concrete project.</p>
<p>jqGrid actually have a lot of features and and you actually can not care about the ids.</p>
<p>If the id is not set or can not be found we use a counter.</p>
<p>I think that you can use the following code from jqGrid</p>
<p><input type='button' class='sfcodeselect' name='sfselectit9420' value='Select Code' data-codeid='sfcode9420' /></p>
<div class='sfcode' id='sfcode9420'>
<p>&#160;&#160;&#160; jqID : function(sid){<br />&#160;&#160; &#160;&#160;&#160; &#160;sid = sid + "";<br />&#160;&#160; &#160;&#160;&#160; &#160;return sid.replace(/([\.\:\[\]])/g,"\\$1");<br />&#160;&#160; &#160;},</p>
</div>
<p>This function can be easy extended with characters what you want to be replaced - i.e after you load jqGrid js files you can do</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3418' value='Select Code' data-codeid='sfcode3418' /></p>
<div class='sfcode' id='sfcode3418'>
<p>$.extend($.jgrid,{</p>
<p>jqID : function (id) {</p>
<p>// your code here</p>
<p>}</p>
</div>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Thu, 25 Mar 2010 09:00:35 +0200</pubDate>
        </item>
        <item>
        	<title>rodk on More on periods/colons in IDs</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15892</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15892</guid>
        	        	<description><![CDATA[<p>OK, I think I&#39;ve come up with a solution to Option A.</p>
<p>As mentioned, Base64 includes 3 characters that are NOT valid in element IDs: &#39;+&#39;, &#39;\&#39; and &#39;=&#39; and we have only two available characters to use to replace them: &#39;-&#39; and &#39;_&#39;.</p>
<p>However, the &#39;=&#39; only appears on the END of the encoding, as padding characters to even the bit count.&#160; So, the solution I&#39;ve devised replaces the &#39;+&#39; and &#39;\&#39; with &#39;_&#39; and &#39;-&#39; respectively and replaces the trailing &#39;=&#39;s with the count of the number of &#39;=&#39;. Since the number of equal signs appearing is either 0, 1 or 2, we know we are never adding more than one character.</p>
<p>Obviously, to decode this, we simply need to replace the last character with the number of =s it designates, replace the &#39;_&#39; and &#39;-&#39; with &#39;+&#39; and &#39;\&#39; respecively and base64 decode the resulting string to get back our original ID.</p>
</p>
<p>The following two functions in PHP will do just that:</p>
</p>
<p>function idencode($s) {<br />&#160;&#160; &#160;$r = base64_encode($s);<br />&#160;&#160; &#160;// replace + and /<br />&#160;&#160; &#160;$r = str_replace(&#39;+&#39;, &#39;_&#39;, $r);<br />&#160;&#160; &#160;$r = str_replace(&#39;/&#39;, &#39;-&#39;, $r);<br />&#160;&#160; &#160;// replace trailing "=" with the count of number of "="<br />&#160;&#160; &#160;$eqpos = strpos($r, &#39;=&#39;);<br />&#160;&#160; &#160;if($eqpos===false) {<br />&#160;&#160; &#160;&#160;&#160; &#160;$count = 0;<br />&#160;&#160; &#160;}<br />&#160;&#160; &#160;else {<br />&#160;&#160; &#160;&#160;&#160; &#160;$count = strlen($r) - $eqpos;<br />&#160;&#160; &#160;&#160;&#160; &#160;// remove =<br />&#160;&#160; &#160;&#160;&#160; &#160;$r = str_replace(&#39;=&#39;, &#39;&#39;, $r);<br />&#160;&#160; &#160;}<br />&#160;&#160; &#160;// add count<br />&#160;&#160; &#160;$r .= $count;<br />&#160;&#160; &#160;return $r;<br />}</p>
<p>function iddecode($s) {<br />&#160;&#160; &#160;print "$s\n\n";<br />&#160;&#160; &#160;// replace "=" at end<br />&#160;&#160; &#160;$count = substr($s, -1);<br />&#160;&#160; &#160;$r = substr($s, 0, -1);<br />&#160;&#160; &#160;if($count&#62;0) {<br />&#160;&#160; &#160;&#160;&#160; &#160;for($i=0;$i&#60;$count;$i++) {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$r .= &#39;=&#39;;<br />&#160;&#160; &#160;&#160;&#160; &#160;}<br />&#160;&#160; &#160;}<br />&#160;&#160; &#160;// replace - and _<br />&#160;&#160; &#160;$r = str_replace(&#39;_&#39;, &#39;+&#39;, $r);<br />&#160;&#160; &#160;$r = str_replace(&#39;-&#39;, &#39;/&#39;, $r);<br />&#160;&#160; &#160;return base64_decode($r);<br />}</p>
</p>
<p>So far, my tests using this with jqGrid have been successful.</p>
</p>
<p>Tony, you might want to consider adding this to the documentation.</p>
]]></description>
        	        	<pubDate>Mon, 22 Mar 2010 18:16:55 +0200</pubDate>
        </item>
        <item>
        	<title>rodk on More on periods/colons in IDs</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15891</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/more-on-periodscolons-in-ids#p15891</guid>
        	        	<description><![CDATA[<p>Using jqGrid 3.6.4</p>
<p>In addition to my previously reported problems with having periods in the ID, simply using a function to escape the periods and colons is not a complete solution.&#160; Many places in the code of jqGrid appear to use the unescaped ID and I would imagine changing this would be a major undertaking.&#160; However, there are a multitude of characters that are technically invalid to be used in HTML element ID attributes, which are limited by the SGML NAME standard (must start with a letter and contain only letters, numbers, hyphens, underscores, colons and dots.&#160; However, from a data standpoint, the ID that the server (i.e. a database schema) uses could contain just about any character.&#160; Obviously these two paradigms are going to create a HUGE problem.&#160; Unless one subscribes to the notion that EVERY db table contain an auto-increment/sequence as the PK (I won&#39;t get into debating the merits or lack thereof here).</p>
</p>
<p>As I see it, the only two possibilities for fixing this error are:</p>
<p>A) the developer must find someway to encode the ID so that it does not  contain any characters which may cause problems.</p>
<p>B) jqGrid must not base HTML element IDs on the ID from the data.</p>
</p>
<p>I shall look into option A and report back my progress.&#160; Base64 encoding has SOME possibilities.&#160; Unfortunately, Base64 encoded output contains 3 illegal characters: +, / and = (= used for padding).&#160; Those could be replaced with valid characters, except the only characters allowed for an ID attribute that aren&#39;t already part of Base64 encoding are hyphens, underscores, periods and colons.&#160; Since periods and colons are out, we only have two possible values to replace 3 characters.</p>
</p>
<p>Option B is beyond my perview.&#160; However, not being familiar with the code (and lacking a strong enough background in JS) I wonder if it might be possible to use generated IDs rather than using the row_id as the basis of creating the element iDs?&#160; Having just started with jqGrid, I&#39;m not sure where this might introduce a problem.&#160; For subgrids, the function defined in subGridRowExpanded() is passed the subgrid_id (the div created by jqGrid to contain the subgrid) as well as the row_id.&#160; Obviously this means the subgrid_id does not need to be based on the row_id.</p>
</p>
<p>If someone could point me to where in the code the div ID is determined, I would be happy to test this out by changing the derived ID to a generated ID.</p>
</p>
<p>I suppose I could change all of my thousands of existing DB tables to use sequences for PK but besides grating on my sense of what are and aren&#39;t DB best practices and the amount of work involved, this doesn&#39;t solve the problem for anyone else that may run afoul of this issue.</p></p>
]]></description>
        	        	<pubDate>Mon, 22 Mar 2010 17:23:08 +0200</pubDate>
        </item>
</channel>
</rss>