<?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: New to jQuery Grid</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/new-to-jquery-grid</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/new-to-jquery-grid/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>rogot on New to jQuery Grid</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/new-to-jquery-grid#p24783</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/new-to-jquery-grid#p24783</guid>
        	        	<description><![CDATA[<p>I am using jQuery Grid for the first time and I am having trouble getting it to do what I want.</p>
<p>I want the grid to appear when my page is loaded populated, by a json object which is derived from a generic list of objects (C#) held in&#160; a session variable on teh server. If the session variable is empty it is fine for an empty grid to be displayed.</p>
<p>I also want users to be able to add or removed rows in the grid. Rows can be added by entering parameters for various fields and posting them to&#160;the server where a database query is performed. The results of this query are added to the session variable and the new value of the variable is sent back to the grid.</p>
<p>What I am finding is that I can do either of these things separately but I can&#39;t get both to happen from the same page. It is as though the page&#160;is in a state after the first retrieve (which is a GET action) that makes it unable to do the second retrieve (which is a POST). I can see that the function to display the grid is being reached the second time, but the nothing happens on the server.</p>
<p>My code is below, apologies if the formatting makes it difficult to follow.</p>
<p>Any help would be appreciated.</p>
</p>
<p>Here is the script to call the grid display functon:</p>
</p>
<p>&#60;script type="text/javascript"&#62;</p>
<p>&#160;&#160; $(document).ready(function() {&#160;</p>
<p>&#160;&#160;&#160;&#160;&#160; ShowGrid("json", "GET");</p>
<p>&#160;&#160;&#160;&#160;&#160; $("#btnAdd").click(function(event) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ShowGrid("json", "POST");</p>
<p>&#160;&#160;&#160;&#160;&#160; });</p>
<p>&#160;&#160; });&#160;</p>
<p>&#60;/script&#62;</p>
</p>
<p>Here is the grid:</p>
</p>
<p>&#60;script type="text/javascript"&#62;</p>
<p>&#160;&#160; function ShowGrid(dataType, mType){</p>
<p>&#160;&#160;&#160;&#160;&#160; var jqDataUrl = "AddWork";</p>
<p>&#160;&#160;&#160;&#160;&#160; $("#jqTable").jqGrid({</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; url: jqDataUrl,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; datatype: dataType,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; mtype: mType,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; colNames: ["IRN", "Parent", "AccNo", "Creator", "Title", "Date"],</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; colModel: [</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ name: "IRN", index: "IRN", width: 8, align: "left" },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { name: "ParentIRN", index: "ParentIRN", width: 12, align: "left" },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { name: "AccNo", index: "AccNo", width: 20, align: "left" },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { name: "Creator", index: "Creator", width: 30, align: "left" },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{ name: "Title", index: "Title", width: 100, align: "left" },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { name: "Date", index: "Date", width: 10, align: "left" }],</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; width: 1200,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; height: 500,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; multiselect: true,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; viewrecords: true,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; scroll:true,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; rowNum: -1,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; gridview: true,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; multikey: shiftKey,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; sortname: "IRN",</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; sortorder: "asc",</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; postData: { Artist: $("#Artist").val(), Title: $("#Title").val(), AccNo: $("AccNo").val(), Irn: $("Irn").val() }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; });</p>
<p>&#160;&#160; }</p>
<p>&#60;/script&#62;</p>
</p>
<p>Here is the MVC server side function:</p>
</p>
<p>public ActionResult AddWork(string sidx, string sord, int page, int rows, string[] postData, string Artist, string Title, string Irn, string AccNo )</p>
<p>{</p>
<p>if (Request.HttpMethod == "POST")</p>
<p>{</p>
<p>&#160;&#160;&#160; string irn = Irn == null ? null : Irn;</p>
<p>&#160;&#160;&#160; string accNo = AccNo == null ? null : AccNo;</p>
<p>&#160;&#160;&#160; string artist = Artist == "" ? null : Artist;</p>
<p>&#160;&#160;&#160; string title = Title == "" ? null : Title;</p>
<p>&#160;&#160;&#160; IList&#60;ImagingWork&#62; works = cmsWorksConverter.ConvertToImagingWorks(this.cMSWorkRepository.GetWorks (irn,accNo,&#160;artist, title));</p>
<p>&#160;if (this.sessionWrapper.ImagingWorks != null)</p>
<p>{</p>
<p>&#160;&#160;&#160;&#160; foreach (ImagingWork work in works)</p>
<p>&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160; this.sessionWrapper.ImagingWorks.Add(work);</p>
<p>&#160;&#160;&#160; }</p>
<p>}</p>
<p>else</p>
<p>&#160;&#160;&#160;&#160;&#160; this.sessionWrapper.ImagingWorks = works;</p>
<p>}</p>
<p>if (this.sessionWrapper.ImagingWorks != null)</p>
<p>{</p>
<p>&#160;&#160;&#160;&#160; var imagingWorks = this.sessionWrapper.ImagingWorks.AsQueryable();</p>
<p>&#160;&#160;&#160;&#160; // Send the data to the jQGrid</p>
<p>&#160;&#160;&#160;&#160; var jsonData = new</p>
<p>&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; total = "",</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; page = "",</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; records = "",</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rows = (from work in imagingWorks</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; select new</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Id = GetId(),</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cell = new string[]{</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; work.IRN,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; work.ParentIRN,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; work.AccNo,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; work.Creator,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; work.Title,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; work.Date</p>
<p>&#160;&#160;&#160;&#160;&#160; }).ToArray()</p>
<p>&#160;&#160;&#160; };</p>
<p>&#160;&#160;&#160; return Json(jsonData);</p>
<p>&#160; }</p>
<p>&#160;&#160;&#160; return null;</p>
<p>}</p>
]]></description>
        	        	<pubDate>Sat, 01 Oct 2011 13:08:06 +0300</pubDate>
        </item>
</channel>
</rss>