<?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: Perl -&#62; JSON -&#62; JQGrid</title>
	<link>http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid</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/discussion/perl-json-jqgrid/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>Mose on Perl -&#62; JSON -&#62; JQGrid</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid#p23331</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid#p23331</guid>
        	        	<description><![CDATA[<p>This is the script I am currently working on.&#160; I am being inundated with newline characters and escaped qoutes which are not returning a valid JSON response:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4938' value='Select Code' data-codeid='sfcode4938' /></p>
<div class='sfcode' id='sfcode4938'>
<p>#!/usr/bin/perl <br />use CGI;<br />use DBI;<br />use JSON;<br />use Test::JSON;<br />use POSIX qw(ceil);<br />use strict;<br />use warnings;</p>
<p>my $cgi = CGI-&#62;new;<br />my $page = $cgi-&#62;param(&#39;page&#39;);<br />my $limit = $cgi-&#62;param(&#39;limit&#39;);<br />my $sidx = $cgi-&#62;param(&#39;sidx&#39;);<br />my $sordx = $cgi-&#62;param(&#39;sordx&#39;);</p>
<p>if(!$sidx) {$sidx = 1};<br />my $start = $limit*$page - $limit;</p>
<p>my $dbh = DBI-&#62;connect(&#39;dbi:mysql:hostname=test;database=test&#39;,&#34;test&#34;,&#34;test&#34;) or die $DBI::errstr;<br />my $count = $dbh-&#62;selectrow_array(&#34;SELECT COUNT(id) AS count FROM test;&#34;);<br />my $sql = &#34;SELECT ID, title FROM test ORDER BY ? ? LIMIT ?, ?;&#34;;<br />my $sth = $dbh-&#62;prepare($sql) or die $dbh-&#62;errstr;</p>
<p>$sth-&#62;execute($sidx,$sordx,$start,$limit) or die $sth-&#62;errstr;<br />my $total_pages;<br />if( $count &#62;0 ) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $total_pages = ceil($count/$limit);<br />} else {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $total_pages = 0;<br />}<br />if ($page &#62; $total_pages){ $page=$total_pages};<br />$start = $limit*$page - $limit;<br />my $i=0;<br />my $test;<br />my $response = {};<br />$response-&#62;{page} = $page;<br />$response-&#62;{total} = $total_pages;<br />$response-&#62;{records} = $count;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; while (my $row = $sth-&#62;fetchrow_arrayref) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; my @arr = @{$row};<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; s/\n/\\n/g for $response-&#62;{rows}[$i]{id} = $row-&#62;[0];<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; s/\n/\\n/g for $response-&#62;{rows}[$i]{cell} = \@arr;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $i++;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />my $json = JSON-&#62;new;<br />print $cgi-&#62;header(-type =&#62; &#34;application/json&#34;, -charset =&#62; &#34;utf-8&#34;);<br />my $json_text = $json-&#62;encode($response);<br />Test::JSON::is_valid_json $json_text;</p>
</div>
<p>I&#39;ll try to see if there is anything in your code example I can implement to rectify the issue.</p>
]]></description>
        	        	<pubDate>Thu, 26 May 2011 02:21:36 +0300</pubDate>
        </item>
        <item>
        	<title>laidback01 on Perl -&#62; JSON -&#62; JQGrid</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid#p23329</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid#p23329</guid>
        	        	<description><![CDATA[<p>So, basically you&#39;ll want to query your data however you do &#8211; DBI, DBIx::Class, Rose::DB, whatever.&#160; Load your resultset to a hash, then use JSON, and send it.&#160; I can&#39;t look at the example provided because the link doens&#39;t do what you think it will.&#160; Here&#39;s some early, extremely verbose (ugly) code to do what I said&#8230; However, it&#39;s the most straighforward stuff I have.&#160; YMMV.&#160; I&#39;m using this in a catalyst project, but you can get the gist.</p>
<p> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; my $dtf = $c-&#62;model(&#39;CommonDB&#39;)-&#62;storage-&#62;datetime_parser;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my $rs =<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160; $c-&#62;{result_rs}<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160; -&#62;procure_avoximeter_results( $dtf, $form_query-&#62;valid, );<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160; <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my %results_hash;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my @results_array;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$rs-&#62;result_class(&#39;DBIx::Class::ResultClass::HashRefInflator&#39;);<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;while ( my $hashref = $rs-&#62;next ) {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my $operator = $c-&#62;{&#39;avoximeter_operators&#39;}-&#62;{ $hashref-&#62;{&#39;Avoximeter1000ePatientData&#39;}-&#62;{&#39;user_id&#39;} };<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$results_hash{ $hashref-&#62;{&#39;result_id&#39;} } =<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160; {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160; &#160;&#160; &#160;result_id&#160;&#160; =&#62; $hashref-&#62;{&#39;result_id&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;warnings&#160;&#160;&#160; =&#62; $hashref-&#62;{&#39;warnings&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;facility&#160;&#160;&#160; =&#62; $c-&#62;{&#39;facility_name_hr&#39;}-&#62;{ $hashref-&#62;{&#39;facility_id&#39;} },<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;department&#160; =&#62; $c-&#62;{&#39;department_name_hr&#39;}-&#62;{ $hashref-&#62;{&#39;department_id&#39;} },<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;comment&#160;&#160;&#160;&#160; =&#62; ($hashref-&#62;{&#39;comment&#39;}) ? "Yes" : "No",<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;_th_b_g_dl&#160; =&#62; $hashref-&#62;{&#39;Avoximeter1000ePatientData&#39;}-&#62;{&#39;th_b_g_dl&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;_hb02&#160;&#160;&#160;&#160;&#160;&#160; =&#62; $hashref-&#62;{&#39;Avoximeter1000ePatientData&#39;}-&#62;{&#39;hb02&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;_patient_id =&#62; $hashref-&#62;{&#39;Avoximeter1000ePatientData&#39;}-&#62;{&#39;patient_id&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;_sample_datetime =&#62; $hashref-&#62;{&#39;Avoximeter1000ePatientData&#39;}-&#62;{&#39;sample_datetime&#39;},<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; upload_status&#160;&#160; =&#62; ( $hashref-&#62;{&#39;lis_upload_status&#39;} ) ? $hashref-&#62;{&#39;lis_upload_status&#39;} : "Not uploaded",<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; operator&#160;&#160;&#160; =&#62; ( $operator-&#62;{&#39;f_name&#39;} &#38;&#38; $operator-&#62;{&#39;l_name&#39;} ) ? "$operator-&#62;{&#39;f_name&#39;} $operator-&#62;{&#39;l_name&#39;}" :&#160; $operator-&#62;{&#39;f_name&#39;},<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160; };<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;push (@results_array, $results_hash{ $hashref-&#62;{&#39;result_id&#39;} }&#160; );</p>
<p>&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;};<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my %list_hash;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$list_hash{&#39;total_count&#39;} = @results_array;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;$list_hash{&#39;list&#39;} = \\@results_array;&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my $json = JSON-&#62;new;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;my $results_json = $json-&#62;encode( \\%list_hash ); </p>
<p>Anyway, the jqGrid config that works with the above:</p>
<p>&#60;script type="text/javascript"&#62;</p>
<p>var data = [% results_json %];</p>
<p>jQuery(document).ready(function() {<br />&#160; jQuery("#results").jqGrid({<br />&#160;&#160;&#160; datatype: &#39;jsonstring&#39;,<br />&#160;&#160;&#160; datastr: data,<br />&#160;&#160;&#160; cellEdit: true,<br />&#160;&#160;&#160; cellurl:"[% c.uri_for(&#39;/rpc/AvoxPatDat/update&#39;) %]",<br />&#160;&#160;&#160; colNames:[&#39;result_id&#39;,&#39;Date Performed&#39;,&#39;Patient ID&#39;,&#39;Thb (g/dL)&#39;, &#39;%HbO2&#39;, &#39;Warnings&#39;, &#39;Operator&#39;, &#39;Comment&#39; ],<br />&#160;&#160;&#160; colModel :[ <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;result_id&#39;, index:&#39;result_id&#39;, width:1, hidden:true, key:true},<br />&#160;&#160;&#160;&#160;&#160; {name:&#39;_sample_datetime&#39;, index:&#39;_sample_datetime&#39;, width:130 }, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;_patient_id&#39;, index:&#39;_patient_id&#39;, width:90}, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;_th_b_g_dl&#39;, index:&#39;_th_b_g_dl&#39;, width:90 }, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;_hb02&#39;, index:&#39;_hb02&#39;, width:80 }, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;warnings&#39;, index:&#39;warnings&#39;, width:90 },<br />&#160;&#160;&#160;&#160;&#160; {name:&#39;operator&#39;, index:&#39;operator&#39;, width:100, editable:true },<br />&#160;&#160;&#160;&#160;&#160; {name:&#39;comment&#39;,index:&#39;comment&#39;,width:80, editable:true&#160; },<br />&#160;&#160;&#160; ],<br />&#160;&#160;&#160; rowNum: [% total_count %],<br />&#160;&#160;&#160; sortname: &#39;result_id&#39;,<br />&#160;&#160;&#160; sortorder: &#39;asc&#39;,<br />&#160;&#160;&#160; viewrecords: true,<br />&#160;&#160;&#160; forceFit: true,<br />&#160;&#160;&#160; jsonReader : {<br />&#160;&#160;&#160;&#160;&#160; root:"list",<br />&#160;&#160;&#160;&#160;&#160; records:"total_count",<br />&#160;&#160;&#160;&#160;&#160; repeatitems: false,<br />&#160;&#160;&#160;&#160;&#160; id: "result_id",<br />&#160;&#160;&#160; },<br />&#160;&#160;&#160; height: $("#table_container").height(),<br />&#160;&#160;&#160; caption: &#39;[% total_count %][% total_count == 1 ? " result&#160; " : "&#160; results&#160; " %] returned&#39;,<br />&#160;&#160;&#160; <br />&#160; });<br />});</p>
<p>&#60;/script&#62; </p>
<p>hopefully it&#39;s enough to make sense of it.</p>
]]></description>
        	        	<pubDate>Thu, 26 May 2011 00:38:38 +0300</pubDate>
        </item>
        <item>
        	<title>Mose on Perl -&#62; JSON -&#62; JQGrid</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid#p23191</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/perl-json-jqgrid#p23191</guid>
        	        	<description><![CDATA[<p>I&#39;m trying to set up a basic grid using Perl CGI.&#160; I&#39;m having a hard time converting the PHP code from <a href="http://www.trirand.com/blog/jqgrid/jqgrid.html" rel="nofollow" target="_blank"><a href="http://www.trirand.com/blog/jq" rel="nofollow">http://www.trirand.com/blog/jq</a>.....qgrid.html</a> to Perl.</p>
</p>
<p>I was wondering if anyone was building this with Perl that might share a sniplet as I am having trouble getting this to work.</p>
]]></description>
        	        	<pubDate>Mon, 16 May 2011 05:12:42 +0300</pubDate>
        </item>
</channel>
</rss>