<?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: Hidden variable does not persist in add form after first initial load</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/hidden-variable-does-not-persist-in-add-form-after-first-initial-load</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/hidden-variable-does-not-persist-in-add-form-after-first-initial-load/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>gena_mak on Hidden variable does not persist in add form after first initial load</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/hidden-variable-does-not-persist-in-add-form-after-first-initial-load#p27420</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/hidden-variable-does-not-persist-in-add-form-after-first-initial-load#p27420</guid>
        	        	<description><![CDATA[<p>Hi,</p>
<p>I am new to jqGrid and need help.</p>
<p>I am using the latest 4.4.1 version of jqGrid and Coldfusion 9. My grid so far works as intended however, I am stuck with couple of issues.</p>
<p>1. This is more important issue. Every time I click on Add button to bring add form I must pass one hidden variable "provider_id" taken from drop down box to processing function.</p>
<p>Also, there is a default set in one of the fields for current year that pre-populates Year text box in the add form.</p>
<p>The issue is, when I call add form first time, it works great and I can add new record. Second time when I call add form, that hidden variable is gone and current year does not show too. Also, if I call edit form and update something or, just close it, after that add form behaves the same and does not retain that hidden variable or, pre-populates current year. I can call "edit form" as many times and it works fine.</p>
<p>Bottom line, "add form" loads hidden variable "provider_id" and pre-populates current year only first initial time I call it.</p>
</p>
<p>2. My grid is located in function loadGrid() and called every time parameters change in one of the 3 drop down boxes. The grid is generated just fine when I call it first time from onchange event but, nothing happens when I change second time. I added $("#list").jqGrid(&#39;GridUnload&#39;); line&#160;and, it takes care of it, grid reloads just fine but, I feel this is not correct method to refresh the grid. Also, if I initialize it var grid = $("#list"); it does not refresh either.</p>
<p>Here is the code:</p>
<p>=============================================================================</p>
<blockquote>
<p>&#160;&#60;script type="text/javascript"&#62;<br />&#160;jQuery(document).ready(function(){<br />&#160;&#160;$(&#39;#provider_id&#39;).change(function(){<br />&#160;&#160;&#160;var prID = $(&#39;#provider_id&#39;).val();<br />&#160;&#160;&#160;var mn = $(&#39;#month&#39;).val();<br />&#160;&#160;&#160;var yr = $(&#39;#year&#39;).val();<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;loadGrid(prID,mn,yr);<br />&#160;&#160;});<br />&#160;&#160;<br />&#160;&#160;$(&#39;#month&#39;).change(function(){<br />&#160;&#160;&#160;var prID = $(&#39;#provider_id&#39;).val();<br />&#160;&#160;&#160;var mn = $(&#39;#month&#39;).val();<br />&#160;&#160;&#160;var yr = $(&#39;#year&#39;).val();<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;loadGrid(prID,mn,yr);<br />&#160;&#160;});<br />&#160;&#160;<br />&#160;&#160;$(&#39;#year&#39;).change(function(){<br />&#160;&#160;&#160;var prID = $(&#39;#provider_id&#39;).val();<br />&#160;&#160;&#160;var mn = $(&#39;#month&#39;).val();<br />&#160;&#160;&#160;var yr = $(&#39;#year&#39;).val();<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;loadGrid(prID,mn,yr);<br />&#160;&#160;});<br />&#160;&#160;<br />&#160;&#160;function loadGrid(prID,mn,yr){<br />&#160;&#160;&#160;//var grid = $("#list");<br />&#160;&#160;&#160;//$.jgrid.formatter.integer.thousandsSeparator = &#39;,&#39;;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;//$.jgrid.formatter.number.thousandsSeparator = &#39;,&#39;;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;//$.jgrid.formatter.currency.thousandsSeparator = &#39;,&#39;;<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;//$myGrid = $("#list"),<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //selRowData = null;<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;var arrMonths = {&#39;1&#39;:&#39;January&#39;,&#39;2&#39;:&#39;February&#39;,&#39;3&#39;:&#39;March&#39;,&#39;4&#39;:&#39;April&#39;,&#39;5&#39;:&#39;May&#39;,&#39;6&#39;:&#39;June&#39;,&#39;7&#39;:&#39;July&#39;,&#39;8&#39;:&#39;August&#39;,&#39;9&#39;:&#39;September&#39;,&#39;10&#39;:&#39;October&#39;,&#39;11&#39;:&#39;November&#39;,&#39;12&#39;:&#39;December&#39;};<br />&#160;&#160;&#160;var arrStatus = {&#39;B&#39;:&#39;Billed&#39;,&#39;P&#39;:&#39;Paid&#39;};<br />&#160;&#160;&#160;var currentTime = new Date()<br />&#160;&#160;&#160;var currYear = currentTime.getFullYear()<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;$("#list").jqGrid(&#39;GridUnload&#39;); &#160;// reload grid<br />&#160;&#160;&#160;$("#list").jqGrid(<br />&#160;&#160;&#160;{<br />&#160;&#160;&#160;&#160;<a href="/blog/&#39;../components/accnt/accnttrx.cfc?method=GetTranactions&#38;prID=&#39;" target="_blank">url:&#39;../components/accnt/accnttrx.cfc?method=GetTranactions&#38;prID=&#39;</a> + prID + &#39;&#38;mn=&#39; + mn + &#39;&#38;yr=&#39; + yr, //CFC that will return the users<br />&#160;&#160;&#160;&#160;datatype: &#39;json&#39;, //We specify that the datatype we will be using will be JSON<br />&#160;&#160;&#160;&#160;colNames:[&#39;Trx ID&#39;,&#39;Cheque No&#39;,&#39;Amount&#39;, &#39;Debit&#39;,&#39;Credit&#39;, &#39;Month&#39;, &#39;Year&#39;, &#39;Status&#39;,&#39;Added by Employee&#39;,&#39;trx_employee_id&#39;,&#39;sponsor_id&#39;,&#39;division_id&#39;,&#39;plan_id&#39;,&#39;provider_id&#39;], //Column Names<br />&#160;&#160;&#160;&#160;//The Column Model to define the data. Note you can make columns non sortable, specify width, alignment, etc.<br />&#160;&#160;&#160;&#160;colModel :[<br />&#160;&#160;&#160;&#160; {name:&#39;accttrx_id&#39;,index:&#39;accttrx_id&#39;, width:75, sorttype:"int",editable:true,searchoptions:{sopt:[&#39;eq&#39;,&#39;lt&#39;,&#39;le&#39;,&#39;gt&#39;,&#39;ge&#39;]}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;cheque_no&#39;,index:&#39;cheque_no&#39;, width:150, sorttype:"text",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;//formatter: &#39;date&#39;, formatoptions: {newformat: &#39;d-M-Y&#39;}, datefmt: &#39;d-M-Y&#39;<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;cheque_amt&#39;,index:&#39;cheque_amt&#39;, width:150, align:"right",formatter: &#39;number&#39;,sorttype:"number",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;debit&#39;,index:&#39;debit&#39;, width:150, align:"right",formatter:&#39;number&#39;,sorttype:"number",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;credit&#39;,index:&#39;credit&#39;, width:150, align:"right",formatter:&#39;number&#39;,sorttype:"number",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;accttrx_month&#39;,index:&#39;accttrx_month&#39;, width:150,align:"left",sorttype:"int",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:true,formatter: &#39;select&#39;,edittype:"select",editoptions:{value:arrMonths},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;accttrx_year&#39;,index:&#39;accttrx_year&#39;, width:40,align:"left",sorttype:"int",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:true,edittype:"text",editoptions:{value:currYear,size:30},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;accttrx_status&#39;,index:&#39;accttrx_status&#39;, width:150,align:"left",sorttype:"text",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]},formatter: &#39;select&#39;,editable:true,edittype:"select",editoptions:{value:arrStatus},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;ee_name&#39;,index:&#39;ee_name&#39;, width:150,align:"left",sorttype:"text",searchoptions:{sopt:[&#39;eq&#39;,&#39;bw&#39;,&#39;ew&#39;,&#39;cn&#39;]}, editable:false,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;trx_employee_id&#39;, editable:true, hidden:true},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;sponsor_id&#39;, editable:true, hidden:true},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;division_id&#39;, editable:true, hidden:true},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;plan_id&#39;, editable:true, hidden:true},<br />&#160;&#160;&#160;&#160;&#160;{name:&#39;provider_id&#39;,editoptions:{value:$(&#39;#provider_id&#39;).val()}, editable:true, hidden:true}<br />&#160;&#160;&#160;&#160;], // hidden variable used in add form to add new record</p>
<p>//searchoptions parameter is used to limit the operators available during search<br />&#160;&#160;&#160;&#160;pager: $(&#39;#pager&#39;), //The div we have specified, tells jqGrid where to put the pager<br />&#160;&#160;&#160;&#160;rowNum:20, //Number of records we want to show per page<br />&#160;&#160;&#160;&#160;rowList:[20,30,40,50], //Row List, to allow user to select how many rows they want to see per page<br />&#160;&#160;&#160;&#160;sortorder: "asc", //Default sort order<br />&#160;&#160;&#160;&#160;ondblClickRow: function (rowid, iRow, iCol, e) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; alert(rowid);&#160;// to populate with logs<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; },<br />&#160;&#160;&#160;&#160;sortname: "accttrx_id", //Default sort column<br />&#160;&#160;&#160;&#160;viewrecords: true, //Shows the nice message on the pager<br />&#160;&#160;&#160;&#160;//imgpath: &#39;/Test/themes/basic/images&#39;, //Image path for prev/next etc images<br />&#160;&#160;&#160;&#160;caption: &#39;Transactions&#39;, //Grid Name<br />&#160;&#160;&#160;&#160;recordtext: "Record {0} &#8211; {1} of {2}",//Pager information to show<br />&#160;&#160;&#160;&#160;rownumbers: false,//Show row numbers<br />&#160;&#160;&#160;&#160;rownumWidth: "30&#8243;,//Width of the row numbers column<br />&#160;&#160;&#160;&#160;sortable: true,<br />&#160;&#160;&#160;&#160;height:&#39;auto&#39;, //I like auto, so there is no blank space between. Using a fixed height can mean either a scrollbar or a blank space before the pager<br />&#160;&#160;&#160;&#160;mtype:&#39;POST&#39;,&#160;<br />&#160;&#160;&#160;&#160;toolbar:[true,"top"], //Shows the toolbar at the top. We will use it to display user feedback<br />&#160;&#160;&#160;&#160;//The JSON reader. This defines what the JSON data returned from the CFC should look like<br />&#160;&#160;&#160;&#160;jsonReader: {<br />&#160;&#160;&#160;&#160;&#160;root: "ROWS", //our data<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; page: "PAGE", //current page<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; total: "TOTAL", //total pages<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; records:"RECORDS", //total records<br />&#160;&#160;&#160;&#160;&#160;userdata:"USERDATA", //Userdata we will pass back for feedback<br />&#160;&#160;&#160;&#160;&#160;cell: "", //Not Used<br />&#160;&#160;&#160;&#160;&#160;id: "0&#8243; //Will default to first column<br />&#160;&#160;&#160;&#160;&#160;},<br />&#160;&#160;&#160;&#160;editurl:"../components/accnt/accnttrx.cfc?method=addeditTrx" //The Add/Edit function call, if set to clientArray then no server connection is established<br />&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;<br />&#160;&#160;&#160;).navGrid(&#39;#pager&#39;,<br />&#160;&#160;&#160;&#160;{<br />&#160;&#160;&#160;&#160;&#160;search:true,searchtitle:"Search",//title set for hover over display<br />&#160;&#160;&#160;&#160;&#160;edit:true,edittitle:"Edit Transation",<br />&#160;&#160;&#160;&#160;&#160;add:true,addtitle:"Add Transaction",<br />&#160;&#160;&#160;&#160;&#160;del:true,deltitle:"Delete Transaction"<br />&#160;&#160;&#160;&#160;},<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<br />&#160;&#160;&#160;// Edit Options. savekey parameter will keybind the Enter key to submit.<br />&#160;&#160;&#160;{beforeShowForm: function(form) { <br />&#160;&#160;&#160;&#160;&#160;$(&#39;#tr_accttrx_id&#39;, form).hide();<br />&#160;&#160;&#160;&#160;&#160;$(&#39;#tr_trx_employee_id&#39;, form).hide(); <br />&#160;&#160;&#160;&#160;&#160;$(&#39;#sponsor_id&#39;, form).hide(); <br />&#160;&#160;&#160;&#160;&#160;$(&#39;#division_id&#39;, form).hide(); <br />&#160;&#160;&#160;&#160;&#160;$(&#39;#plan_id&#39;, form).hide(); <br />&#160;&#160;&#160;&#160;},<br />&#160;&#160;&#160;&#160;editCaption:"Edit Transaction",edittext:"Edit",closeOnEscape:true, savekey: [true,13],errorTextFormat:commonError,width:"450&#8243;,reloadAfterSubmit:true,bottominfo:"Fields marked with (*) are required",top:"60&#8243;,left:"70&#8243;}, <br />&#160;&#160;&#160;{beforeShowForm: function(form) {<br />&#160;&#160;&#160;&#160;&#160;//var&#160; prID = $(&#39;#provider_id&#39;).val();<br />&#160;&#160;&#160;&#160;&#160;$(&#39;#tr_accttrx_id&#39;, form).hide();<br />&#160;&#160;&#160;&#160;&#160;$(&#39;#tr_provider_id&#39;, form).hide();<br />&#160;&#160;&#160;&#160;},<br />&#160;&#160;&#160;&#160;addCaption:"Add Transaction",closeOnEscape:true,savekey: [true,13],errorTextFormat:commonError,width:"450&#8243;,reloadAfterSubmit:true,bottominfo:"Fields marked with (*) are required",top:"60&#8243;,left:"70&#8243;}, //Add Options<br />&#160;&#160;&#160;{url:"../components/accnt/accnttrx.cfc?method=delUser",caption:"Delete Trancaction",closeOnEscape:true,errorTextFormat:commonError,top:"60&#8243;,left:"70&#8243;,reloadAfterSubmit:true}, //Delete Options<br />&#160;&#160;&#160; //Search Options. multipleSearch parameter lets it know we are going to use the new advanced search feature<br />&#160;&#160;&#160;{errorTextFormat:commonError,Find:"Search",closeOnEscape:true,caption:"Search Users",multipleSearch:true,closeAfterSearch:true}<br />&#160;&#160;&#160;);<br />&#160;&#160;&#160;<br />&#160;&#160;&#160;function commonError(data)<br />&#160;&#160;&#160;{&#160;&#160;&#160;<br />&#160;&#160;&#160;&#160;return "Error Occured during Operation. Please try again";<br />&#160;&#160;&#160;}&#160;<br />&#160;&#160;}&#160;&#160;<br />&#160;});<br />&#60;/script&#62;</p>
</blockquote>
<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</p>
<p>&#60;tr&#62;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;td width="300&#8243;&#62;&#60;cfoutput&#62;Provider:&#60;/td&#62;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;td width="400&#8243;&#62;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;cfselect name="provider_id" bind="cfc:components.accnt.accnttrx.GetProviders(#REQUEST.SESS.lang_id#,#REQUEST.SESS.sup_list#)" display="name" value="provider_id" BindOnLoad="true"&#62;&#60;/cfselect&#62;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/td&#62;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;/tr&#62;</p>
<blockquote>
<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..</p>
</blockquote>
<p>Thank you in advance</p>
]]></description>
        	        	<pubDate>Thu, 27 Sep 2012 20:47:15 +0300</pubDate>
        </item>
</channel>
</rss>