<?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: .Net MVC Column Lookup Through Custom Formatter</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/net-mvc-column-lookup-through-custom-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/help/net-mvc-column-lookup-through-custom-formatter/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>Craig831 on .Net MVC Column Lookup Through Custom Formatter</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/net-mvc-column-lookup-through-custom-formatter#p31421</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/net-mvc-column-lookup-through-custom-formatter#p31421</guid>
        	        	<description><![CDATA[<p>I'm building an MVC application for my own use and to learn more about MVC and decided to use jqGrid. Â Nice product, BTW. Â I dig it.</p>
<p>Anyway, I've built all my models and controllers and have grids working for the pages on which I'm going to use them. Â I'm able to display, edit, add, and delete records as expected and I've been successful in wiring up edit forms that use my controllers to populate dropdown options. Â All of that is working great.</p>
<p>The problem I have is when I display each record in the main grid. Â I have two tables, each with corresponding models and controllers. Â Table 1 is Seasons (id, name, start date, end date, frequency). Â Table 2 is Frequency (id and description). Â Basically the frequency is a lookup for values of weekly, bi-weekly, monthly, etc. Â The FrequencyId primary key is a foreign key in the Season table.</p>
<p>When my edit/add form is populated, I use the frequency controller to return an html string of options and that part works great. Â It even populates the correct selection on edit. Â When the grid is displaying each Season row, though, the Frequency field shows the ID. Â I have been searching for a solution and trying many different ways to code this for a couple days now and nothing is working. Â I used "formatter: select" and that just blanked out the field on load and I've recently been trying to use a custom formatter so that I can pass the cell value back to my controller method. Â That's where I'm stuck. Â How do I setup the custom formatter to return aÂ string from the controller instead of just returning the literal string. Â I've tried to use a url property instead of what you see below but haven't had any luck there, either.</p>
<p>Also, am I doing this the right way? Â Am I making it too complicated? Â Is there an easy way to do what I'm trying to do here?</p>
<p>Thanks!</p>
<p>Â </p>
<p>My Seasons ViewModel:</p>
<p>$(function () {<br />
 $("#grid").jqGrid({<br />
 url: "/AdminSeasons/GetSeasons",<br />
 datatype: 'json',<br />
 mType: 'Get',<br />
 colNames: ['SeasonId', 'Season Name', 'Start Date', 'End Date', 'Bowl Frequency', 'Handicap Base Score', 'Handicap Percentage', 'Day Of The Week'],<br />
 colModel: [<br />
 { key: true, name: 'SeasonId', index: 'SeasonId', hidden: true },<br />
 { key: false, name: 'SeasonName', index: 'SeasonName', editable: true },<br />
 {<br />
 editable: true, width: 120, name: "SeasonStartDate", search: false, formatter: "date",<br />
 formatoptions: { srcformat: "m/d/Y h:i:s A", newformat: "Y-m-d" }<br />
 },<br />
 {<br />
 editable: true, width: 120, name: "SeasonEndDate", search: false, formatter: "date",<br />
 formatoptions: { srcformat: "m/d/Y h:i:s A", newformat: "Y-m-d" }<br />
 },<br />
 {<br />
 editable: true, width: 120, name: "FrequencyId", search: false, edittype: "select", formatter: frequencyFormatter,<br />
 editoptions: { dataUrl: "/AdminFrequency/FrequencyList" }<br />
 },<br />
 {<br />
 editable: true, width: 120, name: "HandicapBaseScore", search: false, edittype: "select",<br />
 editoptions: { dataUrl: "/AdminSeasons/HtmlFormattedBaseScoreList" }<br />
 },<br />
 {<br />
 editable: true, width: 120, name: "HandicapPercentage", search: false, edittype: "select",<br />
 editoptions: { dataUrl: "/AdminSeasons/HtmlFormattedPercentageList" }<br />
 },<br />
 {<br />
 editable: true, width: 120, name: "DayOfTheWeekId", search: false, edittype: "select", formatter: "select",<br />
 editoptions: { dataUrl: "/AdminDayOfTheWeek/DayOfTheWeekList" }<br />
 }],<br />
 pager: jQuery("#pager"),<br />
 rowNum: 10,<br />
 rowList: [10, 20, 30, 40],<br />
 height: '100%',<br />
 viewRecords: true,<br />
 caption: 'Manage Seasons',<br />
 emptyRecords: 'No records to display',<br />
 jsonReader: {<br />
 root: 'rows',<br />
 page: 'page',<br />
 total: 'total',<br />
 records: 'records',<br />
 repeatitems: false,<br />
 id: '0'<br />
 },<br />
 autowidth: true,<br />
 multiselect: false<br />
 }).navGrid('#pager', { edit: true, add: true, del: true, search: false, refresh: true },<br />
 {<br />
 // edit options<br />
 zIndex: 100,<br />
 url: '/AdminSeasons/Edit',<br />
 closeOnEscape: true,<br />
 closeAfterEdit: true,<br />
 recreateForm: true,<br />
 //afterComplete: function (response) {<br />
 // if (response.responseText) {<br />
 // alert(response.responseText);<br />
 // }<br />
 //}<br />
 },<br />
 {<br />
 // add options<br />
 zIndex: 100,<br />
 url: '/AdminSeasons/Create',<br />
 closeOnEscape: true,<br />
 closeAfterAdd: true,<br />
 //afterComplete: function (response) {<br />
 // if (response.responseText) {<br />
 // alert(response.responseText);<br />
 // }<br />
 //}<br />
 },<br />
 {<br />
 // delete options<br />
 zIndex: 100,<br />
 url: '/AdminSeasons/Delete',<br />
 closeOnEscape: true,<br />
 closeAfterDelete: true,<br />
 recreateForm: true,<br />
 msg: 'Are you sure you want to delete this season?',<br />
 //afterComplete: function (response) {<br />
 // if (response.responseText) {<br />
 // alert(response.responseText);<br />
 // }<br />
 //}<br />
 });</p>
<p>function frequencyFormatter(cellvalue, options, rowObject) {<br />
 return '/AdminFrequency/FrequencyDescriptById/' + cellvalue;<br />
 //debugger;<br />
 //return frequency;<br />
 }<br />
});</p>
]]></description>
        	        	<pubDate>Wed, 03 Dec 2014 00:03:57 +0200</pubDate>
        </item>
</channel>
</rss>