<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Research ~ A ~ holic &#187; WebApi</title>
	<atom:link href="http://researchaholic.com/tag/webapi/feed/" rel="self" type="application/rss+xml" />
	<link>http://researchaholic.com</link>
	<description>Thoughts by Chad England</description>
	<lastBuildDate>Sat, 18 May 2013 08:23:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='researchaholic.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Research ~ A ~ holic &#187; WebApi</title>
		<link>http://researchaholic.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://researchaholic.com/osd.xml" title="Research ~ A ~ holic" />
	<atom:link rel='hub' href='http://researchaholic.com/?pushpress=hub'/>
		<item>
		<title>Entity Framework 5 easier way to update record</title>
		<link>http://researchaholic.com/2013/02/06/entity-framework-5-easier-way-to-update-record/</link>
		<comments>http://researchaholic.com/2013/02/06/entity-framework-5-easier-way-to-update-record/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 14:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=594</guid>
		<description><![CDATA[In the past with EF if you wanted to update a record you would need to do something like this: public HttpResponseMessage PutCustomer(Customer customer) { using (var context = new ChinookContext()) { var request = context.Customers.Single(c =&#62; c.CustomerId == customer.CustomerId); &#8230; <a href="http://researchaholic.com/2013/02/06/entity-framework-5-easier-way-to-update-record/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=594&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In the past with EF if you wanted to update a record you would need to do something like this:</p>
<p><span id="more-594"></span></p>
<pre class="csharpcode"> <span class="kwrd">public</span> HttpResponseMessage PutCustomer(Customer customer)
        {
            <span class="kwrd">using</span> (var context = <span class="kwrd">new</span> ChinookContext())
            {
                var request = context.Customers.Single(c =&gt; c.CustomerId == customer.CustomerId);

                <span class="rem">// todo this has to have an easier way.  Customer.Attach throws an error</span>
                request.FirstName = customer.FirstName;
                request.LastName = customer.LastName;
                request.Address = customer.Address;
                request.City = customer.City;
                request.PostalCode = customer.PostalCode;
                request.State = customer.State;
                request.Country = customer.Country;
                request.Fax = customer.Fax;
                request.Email = customer.Email;
                request.Company = customer.Company;

                context.SaveChanges();

                var response = Request.CreateResponse(HttpStatusCode.Accepted, customer);
                response.Headers.Location = <span class="kwrd">new</span> Uri(Request.RequestUri, <span class="kwrd">string</span>.Format(<span class="str">"Customer/{0}"</span>, customer.CustomerId));
                <span class="kwrd">return</span> response;
            }
        }</pre>
<p>As you may notice this can get tedious and rather large as more fields need updating.   In Entity Framework 5  we get a wonderful new method ‘SetValues’.  With this new method we can change the above code from that to this:</p>
<pre class="csharpcode"> <span class="kwrd">public</span> HttpResponseMessage PutCustomer(Customer customer)
        {
            <span class="kwrd">using</span> (var context = <span class="kwrd">new</span> ChinookContext())
            {
                var original = context.Customers.Find(customer.CustomerId);

                <span class="kwrd">if</span> (original != <span class="kwrd">null</span>)
                {
                    context.Entry(original).CurrentValues.SetValues(customer);
                    context.SaveChanges();
                }

                var response = Request.CreateResponse(HttpStatusCode.Accepted, customer);
                response.Headers.Location = <span class="kwrd">new</span> Uri(Request.RequestUri, <span class="kwrd">string</span>.Format(<span class="str">"Customer/{0}"</span>, customer.CustomerId));
                <span class="kwrd">return</span> response;
            }
        }</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/594/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/594/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=594&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2013/02/06/entity-framework-5-easier-way-to-update-record/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>
	</item>
		<item>
		<title>.Net 4.5/MVC/WebAPI RC and the missing JsonArray</title>
		<link>http://researchaholic.com/2012/06/22/net-4-5mvcwebapi-rc-and-the-missing-jsonarray/</link>
		<comments>http://researchaholic.com/2012/06/22/net-4-5mvcwebapi-rc-and-the-missing-jsonarray/#comments</comments>
		<pubDate>Fri, 22 Jun 2012 15:20:04 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[JSON.NET]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=359</guid>
		<description><![CDATA[&#160; Before the RC release of MVC4/WebAPI JsonArray and JsonObject lived in System.Runtime.Serialization.&#160; Once you upgrade your project these options disappear. The fix is pretty simple.&#160; In the latest RC release of MVC4/WebApi Microsoft switched the JSON handler to JSON.NET &#8230; <a href="http://researchaholic.com/2012/06/22/net-4-5mvcwebapi-rc-and-the-missing-jsonarray/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=359&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Before the RC release of MVC4/WebAPI JsonArray and JsonObject lived in System.Runtime.Serialization.&nbsp; Once you upgrade your project these options disappear.</p>
<p>The fix is pretty simple.&nbsp; In the latest RC release of MVC4/WebApi Microsoft switched the JSON handler to <a href="http://james.newtonking.com/projects/json-net.aspx" target="_blank">JSON.NET</a></p>
<p><span id="more-359"></span>
<p>The project should have a reference to Newtonsoft.Json (if it does not, you might need to load the NuGet package.</p>
<p>Once this is complete add a using statement</p>
<p>using Newtonsoft.Json.Linq</p>
<p>After that you can now use:</p>
<ul>
<li>JArray in place of JsonArray</li>
<li>JObject in place of JsonObject</li>
<li>so on and so forth.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/359/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=359&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/06/22/net-4-5mvcwebapi-rc-and-the-missing-jsonarray/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 14: Web Api Upgrade from beta to RC</title>
		<link>http://researchaholic.com/2012/06/05/chlodny-series-day-14-web-api-upgrade-from-beta-to-rc/</link>
		<comments>http://researchaholic.com/2012/06/05/chlodny-series-day-14-web-api-upgrade-from-beta-to-rc/#comments</comments>
		<pubDate>Tue, 05 Jun 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=353</guid>
		<description><![CDATA[Over the weekend I finished upgrading the initial parts of the Chlodny Web Api project along with the past blog post of this series.  This post will go over the process I needed to do in order to upgrade from &#8230; <a href="http://researchaholic.com/2012/06/05/chlodny-series-day-14-web-api-upgrade-from-beta-to-rc/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=353&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Over the weekend I finished upgrading the initial parts of the <a href="https://github.com/chadit/ChlodnyWebApi" target="_blank">Chlodny Web Api</a> project along with the past blog post of this series.  This post will go over the process I needed to do in order to upgrade from Web Api Beta to Web Api RC.</p>
<p><span id="more-353"></span></p>
<p>First issue I ran into was that the Nuget packages did not upgrade from Beta to RC.  I found many different ways online to resolve this issue.  In the end I found it the easiest to do the following.</p>
<ol>
<li>Open the packages folder and delete everything.</li>
<li>Start in the Data Access project and upgrade the package.</li>
</ol>
<p>The next thing I ran into for an error was that generic HttpResponseMessage’s were removed. I personally think the new format is a nice change.</p>
<p>The old format looked something like this:</p>
<pre class="csharpcode"><span class="kwrd">new</span> HttpResponseMessage&lt;someGenericCollection&gt;(someValue)</pre>
<p>The new format should look something similar to this:</p>
<pre class="csharpcode">Request.CreateResponse(HttpStatusCode.OK, someMessage)</pre>
<p>&nbsp;</p>
<p>The final upgrade issue I ran into was the removal of GetUserPrincipal.  It was changed to <em>System.Threading.Thread.CurrentPrincipal.Identity</em>.</p>
<p>&nbsp;</p>
<p>Note: As Larry pointed out in the comments his is also exposed to the APIController and is accessible by <em>this.User.Identity </em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/353/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/353/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=353&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/06/05/chlodny-series-day-14-web-api-upgrade-from-beta-to-rc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 13: Web Api Update</title>
		<link>http://researchaholic.com/2012/05/03/chlodny-series-day-13-web-api-update/</link>
		<comments>http://researchaholic.com/2012/05/03/chlodny-series-day-13-web-api-update/#comments</comments>
		<pubDate>Thu, 03 May 2012 15:47:18 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=313</guid>
		<description><![CDATA[[Updated Web Api RC] The last part of the local CRUD application is update.  We will be following a similar pattern that was conducted in Day 12. Open CustomerController.cs and create a new method named PutCustomer that returns a HttpResponseMessage.    &#8230; <a href="http://researchaholic.com/2012/05/03/chlodny-series-day-13-web-api-update/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=313&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>[Updated Web Api RC]</p>
<p>The last part of the local CRUD application is update.  We will be following a similar pattern that was conducted in Day 12.</p>
<p>Open CustomerController.cs and create a new method named PutCustomer that returns a HttpResponseMessage.    In order to improve the user experience, check the passed in customer ID.  Check the database to see if the user exist.  If it does not, it will pass the customer object off  the post method.  If the customer object does exit, it will update the existing customer and save the changes.  If the update is accepted it will pass back the updated customer object and an accepted http response back to the client.</p>
<p><span id="more-313"></span></p>
<p>The PutCustomer method should look similar to the following:</p>
<pre class="csharpcode"><span class="rem">// Update = Put</span>
public HttpResponseMessage PutCustomer(Customer customer)
{
   using (var context = new ChinookContext())
   {
      Customer request = null;

      if (customer.CustomerId != 0)
      {
          request = context.Customers.Single(c =&gt; c.CustomerId == customer.CustomerId);
      }

      if (request == null)
      {
          return this.PostCustomer(customer);
      }

      // todo this has to have an easier way.  Customer.Attach throws an error
         request.FirstName = customer.FirstName;
         request.LastName = customer.LastName;
         request.Address = customer.Address;
         request.City = customer.City;
         request.PostalCode = customer.PostalCode;
         request.State = customer.State;
         request.Country = customer.Country;
         request.Fax = customer.Fax;
         request.Email = customer.Email;
         request.Company = customer.Company;

         context.SaveChanges();

         var response = Request.CreateResponse(HttpStatusCode.Accepted, customer);
         response.Headers.Location = new Uri(Request.RequestUri, string.Format("Customer/{0}", customer.CustomerId));
         return response;
   }
}</pre>
<p>Next a new button to update the selected customer needs to be added to jqueryUILocal.htm.</p>
<p>In the tools div add a new button to the tools div named Edit Customer.</p>
<p>This div should not look like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">="tools"</span> <span class="attr">class</span><span class="kwrd">="tools"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">="newCustomer"</span><span class="kwrd">&gt;</span>New Customer<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">="editCustomer"</span><span class="kwrd">&gt;</span>Edit Customer<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">="removeCustomer"</span><span class="kwrd">&gt;</span>Remove Customer<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">="clearSelection"</span><span class="kwrd">&gt;</span>Clear selection<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
<p>For now below the tools div we will add a new form with the id of editForm.  You can copy the previously created newForm and change the label.  This should look like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="editForm"</span> <span class="attr">title</span><span class="kwrd">="Edit Customer"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">fieldset</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">fieldset</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="submit"</span> <span class="attr">value</span><span class="kwrd">="Save changes"</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span></pre>
<p>In jQueryUIExampleLocal.js it is time to wire up the edit button.  Create a new function with the name of jQueryExample.EditCustomer.  Below is the example followed by the explanation.</p>
<pre class="csharpcode">jQueryExample.EditCustomer = <span class="kwrd">function</span>() {
    <span class="kwrd">var</span> customer;
    $(<span class="str">"#editCustomer"</span>).click(<span class="kwrd">function</span>() {
        <span class="kwrd">if</span> (!selected.length) {
            alert(<span class="str">"None selected"</span>);
            <span class="kwrd">return</span>;
        }
        customer = selected[0];
        $(<span class="str">"#edit-tmpl"</span>).tmpl(meta(customer)).appendTo(editForm.find(<span class="str">"fieldset"</span>).empty());
        editForm.dialog(<span class="str">"open"</span>);
    });
    $(<span class="str">"[type=submit]"</span>).button();
    <span class="kwrd">var</span> editForm = $(<span class="str">"#editForm"</span>).dialog({
        autoOpen: <span class="kwrd">false</span>,
        width: 350,
        modal: <span class="kwrd">true</span>
    }).hide().submit(<span class="kwrd">function</span>(<span class="kwrd">event</span>) {
        <span class="kwrd">event</span>.preventDefault();

        <span class="kwrd">var</span> customerId = $(<span class="str">"#CustomerId"</span>).val();
        <span class="kwrd">var</span> firstName = $(<span class="str">"#FirstName"</span>).val();
        <span class="kwrd">var</span> lastName = $(<span class="str">"#LastName"</span>).val();
        <span class="kwrd">var</span> address = $(<span class="str">"#Address"</span>).val();
        <span class="kwrd">var</span> city = $(<span class="str">"#City"</span>).val();
        <span class="kwrd">var</span> postalCode = $(<span class="str">"#PostalCode"</span>).val();
        <span class="kwrd">var</span> state = $(<span class="str">"#State"</span>).val();
        <span class="kwrd">var</span> country = $(<span class="str">"#Country"</span>).val();
        <span class="kwrd">var</span> email = $(<span class="str">"#Email"</span>).val();
        <span class="kwrd">var</span> phone = $(<span class="str">"#Phone"</span>).val();
        <span class="kwrd">var</span> fax = $(<span class="str">"#Fax"</span>).val();
        <span class="kwrd">var</span> company = $(<span class="str">"#Company"</span>).val();

        <span class="kwrd">var</span> sentData = {
            CustomerId: customerId,
            FirstName: firstName,
            LastName: lastName,
            Address: address,
            City: city,
            PostalCode: postalCode,
            State: state,
            Country: country,
            Email: email,
            Phone: phone,
            Fax: fax,
            Company: company
        };

        $.ajax({ 
            type: <span class="str">'POST'</span>, 
            dataType: <span class="str">'json'</span>, 
            url: <span class="str">'http://localhost:60025/api/customer'</span>, 
            data: sentData }

    );
        $.observable(customer, localCustomers).property(serializeForm(<span class="kwrd">this</span>));
        customers.refresh();
        <span class="rem">// TODO hide tooltip</span>
        editForm.dialog(<span class="str">"close"</span>);
    });
};</pre>
<ul>
<li>Click event is wired to the edit customer button.</li>
<li>Then we verify that a customer has been selected, if not an alert box is displayed</li>
<li>The selected customer is passed to the template and the form is opened.</li>
<li>After the data has been updated, the submit button wraps up the data</li>
<li>An Ajax call with the verb put is sent to the server.</li>
<li>The page collection is then updated and then refreshed</li>
</ul>
<p>We now have a fully working CRUD application that will work on the same domain as the web server.  In the next we series I will demonstrate utilizing cross domain techniques.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=313&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/05/03/chlodny-series-day-13-web-api-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 12: Web Api Create</title>
		<link>http://researchaholic.com/2012/05/01/chlodny-series-day-12-web-api-create/</link>
		<comments>http://researchaholic.com/2012/05/01/chlodny-series-day-12-web-api-create/#comments</comments>
		<pubDate>Tue, 01 May 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=308</guid>
		<description><![CDATA[[Updated to Web Api RC] In our quest to create a CRUD application we have completed the read and the delete portion.  In this article we will generate the create functionality.  For now I am using the jQuery Templates in &#8230; <a href="http://researchaholic.com/2012/05/01/chlodny-series-day-12-web-api-create/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=308&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>[Updated to Web Api RC]</p>
<p>In our quest to create a CRUD application we have completed the read and the delete portion.  In this article we will generate the create functionality.  For now I am using the jQuery Templates in the future I will be switching to something else.</p>
<p><span id="more-308"></span></p>
<p>First thing that needs to be done is to open up the CustomerController.cs in the web api and create a new method with the name of PostCustomer.  It will return an HttpResponseMessage and will look for a parameter of Customer.</p>
<p>To improve on the user experience I am first checking to verify if the customer currently exist.  Going back to my note above, I am doing this in case a user uses the reverse logic then the customer object will be placed in the correct method.</p>
<p>If the user does not exist we will call Entity Framework and execute SaveChanges().  We will then create our HttpResponseMessage and pass in the customer object and an HttpStatusCode.Created.  This is considered good practice for one to notify the contact that something happened and the ajax call can check that the return message was a 201.  jQuery’s ajax call mechanism can check for specific return messaged and conduct different actions.</p>
<p>An example might could be if the message is 201 display a message that says “Customer ID xxxxx has been successfully created.”  Since the customer object with the new ID back is being passed back, the message could display the correct ID.</p>
<p>Included in this HttpResponseMessage the Headers.Localtion with the RequestUri that will give the address to this new user.</p>
<p>The PostCustomer method should look similar to the following:</p>
<pre class="csharpcode"><span class="rem"> // Create = Post</span>
public HttpResponseMessage PostCustomer(Customer customer)
{
   using (var context = new ChinookContext())
   {
       Customer request = null;

       if (customer.CustomerId != 0)
       {
           request = context.Customers.Single(c =&gt; c.CustomerId == customer.CustomerId);
       }

       if (request == null)
       {
           context.Customers.Add(customer);
           context.SaveChanges();

           var response = Request.CreateResponse(HttpStatusCode.Created, customer);
           response.Headers.Location = new Uri(Request.RequestUri, string.Format("Customer/{0}", customer.CustomerId));
           return response;
       }

       return this.PutCustomer(customer);
   }
}</pre>
<p>Now to update the HTML file.</p>
<ul>
<li>Open jqueryUILocal.htm,</li>
<li>In the tools div add a new button to create a new customer.</li>
</ul>
<p>It should look like this now:</p>
<p><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">id</span><span class="kwrd">=&#8221;tools&#8221;</span> <span class="attr">class</span><span class="kwrd">=&#8221;tools&#8221;</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">=&#8221;newCustomer&#8221;</span><span class="kwrd">&gt;</span>New Customer<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">=&#8221;removeCustomer&#8221;</span><span class="kwrd">&gt;</span>Remove Customer<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;</span><span class="html">button</span> <span class="attr">id</span><span class="kwrd">=&#8221;clearSelection&#8221;</span><span class="kwrd">&gt;</span>Clear selection<span class="kwrd">&lt;/</span><span class="html">button</span><span class="kwrd">&gt;</span> <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></p>
<p>Below the tools div</p>
<ul>
<li>Add a form with the id of “newForm”</li>
<li>Add a title of “New Customer”</li>
<li>Add open and close fieldset</li>
<li>add an input of type submit and give it a value of “Save Changes”</li>
</ul>
<p>If should look like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="newForm"</span> <span class="attr">title</span><span class="kwrd">="New Customer"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">fieldset</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">fieldset</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">input</span> <span class="attr">type</span><span class="kwrd">="submit"</span> <span class="attr">value</span><span class="kwrd">="Save changes"</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span></pre>
<p>The last thing that needs to be done in the HTML (when I move off jQuery Templates I will move this out of the html).  we will add out template script.  This will go though the array and generate the fields and labels for the object (or model for those familiar with MVC) passed in.  This code looks like this:</p>
<pre class="csharpcode">&lt;script id=<span class="str">"edit-tmpl"</span> type=<span class="str">"text/x-jsrender"</span>&gt;
  {{<span class="kwrd">if</span> $.isArray(value)}}
  &lt;label&gt;${label}&lt;/label&gt;
  &lt;ul&gt;
      {{each(index, valueX) value}}
      &lt;li&gt;&lt;input type=<span class="str">"text"</span> <span class="kwrd">class</span>=<span class="str">"ui-widget-content ui-corner-all"</span> name=<span class="str">"${name}"</span> placeholder=<span class="str">"${label}"</span> value=<span class="str">"${valueX}"</span> title=<span class="str">"${label}"</span> /&gt;&lt;/li&gt;
      {{/each}}
  &lt;/ul&gt;
  {{<span class="kwrd">else</span>}}
  &lt;label <span class="kwrd">for</span>=<span class="str">"${name}"</span>&gt;${label}&lt;/label&gt;
  &lt;input type=<span class="str">"text"</span> <span class="kwrd">class</span>=<span class="str">"ui-widget-content ui-corner-all"</span> id=<span class="str">"${name}"</span> name=<span class="str">"${name}"</span> placeholder=<span class="str">"${label}"</span> value=<span class="str">"${value}"</span> title=<span class="str">"${label}"</span> /&gt;
  {{/<span class="kwrd">if</span>}}
&lt;/script&gt;</pre>
<p>Now to wire it all the modules together.  Since this part the code is a little long I will post the example first for jQueryUIExampleLocal.js:</p>
<pre class="csharpcode">jQueryExample.NewCustomer = <span class="kwrd">function</span>() {
    $(<span class="str">"#newCustomer"</span>).click(<span class="kwrd">function</span>() {
        <span class="kwrd">var</span> newCustomer = {
            FirstName: <span class="str">""</span>,
            LastName: <span class="str">""</span>,
            Address: <span class="str">""</span>,
            City: <span class="str">""</span>,
            PostalCode: <span class="str">""</span>,
            State: <span class="str">""</span>,
            Country: <span class="str">""</span>,
            Email: <span class="str">""</span>,
            Phone: <span class="str">""</span>,
            Fax: <span class="str">""</span>,
            Company: <span class="str">""</span>
        };

        $(<span class="str">"#edit-tmpl"</span>).tmpl(meta(newCustomer)).appendTo(newForm.find(<span class="str">"fieldset"</span>).empty());
        newForm.dialog(<span class="str">"open"</span>);
    });

    $(<span class="str">"[type=submit]"</span>).button();
    <span class="kwrd">var</span> newForm = $(<span class="str">"#newForm"</span>).dialog({
        autoOpen: <span class="kwrd">false</span>,
        width: 350,
        modal: <span class="kwrd">true</span>
    }).hide().submit(<span class="kwrd">function</span> (<span class="kwrd">event</span>) {
        <span class="kwrd">event</span>.preventDefault();

        <span class="kwrd">var</span> firstName = $(<span class="str">"#FirstName"</span>).val();
        <span class="kwrd">var</span> lastName = $(<span class="str">"#LastName"</span>).val();
        <span class="kwrd">var</span> address = $(<span class="str">"#Address"</span>).val();
        <span class="kwrd">var</span> city = $(<span class="str">"#City"</span>).val();
        <span class="kwrd">var</span> postalCode = $(<span class="str">"#PostalCode"</span>).val();
        <span class="kwrd">var</span> state = $(<span class="str">"#State"</span>).val();
        <span class="kwrd">var</span> country = $(<span class="str">"#Country"</span>).val();
        <span class="kwrd">var</span> email = $(<span class="str">"#Email"</span>).val();
        <span class="kwrd">var</span> phone = $(<span class="str">"#Phone"</span>).val();
        <span class="kwrd">var</span> fax = $(<span class="str">"#Fax"</span>).val();
        <span class="kwrd">var</span> company = $(<span class="str">"#Company"</span>).val();

        <span class="kwrd">var</span> sentData = {
            FirstName: firstName,
            LastName: lastName,
            Address: address,
            City: city,
            PostalCode: postalCode,
            State: state,
            Country: country,
            Email: email,
            Phone: phone,
            Fax: fax,
            Company: company
        };

        $.ajax({ type: <span class="str">'POST'</span>, dataType: <span class="str">'json'</span>, url: <span class="str">'http://localhost:60025/api/customer'</span>, data: sentData,
            success: <span class="kwrd">function</span> (result) {
                $.observable(localCustomers).insert(result);
                customers.refresh();
            }
        });

        newForm.dialog(<span class="str">"close"</span>);
    });
};</pre>
<ul>
<li>Add a new function of jQueryExample.NewCustomer=function(){</li>
<li>Add a click event and define the new customer object</li>
</ul>
<p>Note: Edit is a little easier because we can use the object in the jQuery observable, this was the easiest way I found.  JSRender/JSView might offer an easier or dynamic option.</p>
<ul>
<li>then select the #edit-tmp and pass into the template the newCustomer model</li>
<li>Append it to the newform fieldset</li>
<li>then add a call to the dialog(“open”)</li>
<li>Wireup the submit button</li>
<li>In the submit button grab the values of the form</li>
<li>Package those values in a object called sentData</li>
<li>Call $.ajax with the verb of POST and then the sentData.</li>
<li>Add a success function to the Ajax call.  If no errors are returned the new customer will be added to the observable object that the data grid is bound to.</li>
<li>Call a refresh on the customers collection</li>
<li>and finally close the dialog.</li>
<li>Add jQueryExample.NewCustomer() to the jQueryExample.jQueryWireUp function</li>
</ul>
<p>Run the code, click the New Customer button and the following form should open.</p>
<p><a href="http://chadit.files.wordpress.com/2012/05/croppercapture73.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="CropperCapture[73]" src="http://chadit.files.wordpress.com/2012/05/croppercapture73_thumb.png?w=218&#038;h=373" alt="CropperCapture[73]" width="218" height="373" border="0" /></a></p>
<p>Add some data and click save changes.  In the Grid the new customer should show up.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=308&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/05/01/chlodny-series-day-12-web-api-create/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>

		<media:content url="http://chadit.files.wordpress.com/2012/05/croppercapture73_thumb.png" medium="image">
			<media:title type="html">CropperCapture[73]</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 11: Web Api Delete</title>
		<link>http://researchaholic.com/2012/04/16/chlodny-series-day-11-web-api-delete/</link>
		<comments>http://researchaholic.com/2012/04/16/chlodny-series-day-11-web-api-delete/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=290</guid>
		<description><![CDATA[[Updated for Web Api RC] In sessions 8-10 we added some get functionality along with paging and selection support to our grid.  Now what if we want to prune out customer database and remove one of those customers. In the &#8230; <a href="http://researchaholic.com/2012/04/16/chlodny-series-day-11-web-api-delete/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=290&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>[Updated for Web Api RC]</p>
<p>In sessions 8-10 we added some get functionality along with paging and selection support to our grid.  Now what if we want to prune out customer database and remove one of those customers.</p>
<p><span id="more-290"></span></p>
<ul>
<li>In the Web Api Open CustomerController.cs</li>
<li>Create a new method named DeleteCustomer that excepts an integer of id</li>
<li>DeleteCustomer will also return a HttpResponseMessage</li>
<li>initialize an empty message named reponse</li>
</ul>
<p>In this sample application we do not technically allow anyone except the DBA access to delete records. If you have been following this series we added a new column to our customer database to signify that a record is deleted.  We then modified our Get method not to return those records.</p>
<p>So because of this we are going to do something slightly different.  First we will check to see if the record exist while also checking to ensure it has not already been marked as deleted.  If it has not, then we will set to deleted and return and Accepted 202 HTTP message.  If it has already been deleted or is not found we will return a Not found 404 HTTP message.  Our new deleted method should look similar to this;</p>
<pre class="csharpcode">// Delete = DELETE
public HttpResponseMessage DeleteCustomer(int id)
{
    using (var context = new ChinookContext())
    {
      var request = context.Customers.Single(c =&gt; c.CustomerId == id &amp;&amp; c.Deleted == false);

      if (request != null)
      {
         request.Deleted = true;
         context.SaveChanges();
         return Request.CreateResponse(HttpStatusCode.Accepted, request);
       }
        return Request.CreateResponse(HttpStatusCode.NotFound);
    }
}</pre>
<ul>
<li>Open up jQueryUILocal.htm</li>
<li>In the tools div tab we created in Day 10 add a new button with the id removeCustomer.</li>
</ul>
<pre class="csharpcode">&lt;div <span class="kwrd">class</span>=<span class="str">"tools"</span>&gt;
        &lt;button id=<span class="str">"removeCustomer"</span>&gt;Remove Customer&lt;/button&gt;
        &lt;button id=<span class="str">"clearSelection"</span>&gt;Clear selection&lt;/button&gt;
    &lt;/div&gt;</pre>
<ul>
<li>Open Up jQueryUIExampleLocal.js</li>
<li>Create a new function in our jQueryExample and name it Remove Button</li>
<li>Add the follow code to the function</li>
</ul>
<pre class="csharpcode">jQueryExample.RemoveButton = <span class="kwrd">function</span> () {
    $(<span class="str">"#removeCustomer"</span>).click(<span class="kwrd">function</span> () {
        <span class="kwrd">if</span> (!selected.length) {
            alert(<span class="str">"None selected"</span>);
            <span class="kwrd">return</span>;
        }
        <span class="kwrd">var</span> customerId = selected[0].CustomerId;
        $.ajax({ type: <span class="str">"DELETE"</span>, url: <span class="str">"http://localhost:60025/api/customer/"</span> + customerId });

        $.observable(localCustomers).remove(selected);
        $.observable(selected).remove(0, selected.length);
        customers.refresh();
    });
};</pre>
<p>In this function we do a few things.</p>
<p>First we check upon click if something has been selected.  If not we display an alert box (I am not a fan of alert boxes so this will be changed later).</p>
<p>Currently this function only supports deleting one record at a time, it could be easily expanded to allow multiple deletes.</p>
<p>The function then removes the row from the client side dataview and refresh the object.</p>
<p>To finish up we need to add this new function to our jQueryWireUp, it should now look like this:</p>
<pre class="csharpcode">jQueryExample.jQueryWireUp = <span class="kwrd">function</span> () {
    jQueryExample.GetAllCustomer();
    jQueryExample.LoadDataView();
    jQueryExample.LoadDataGrid();
    jQueryExample.PageSizeOptions();
    jQueryExample.SelectedGridOptions();

    customers.refresh();

    jQueryExample.RemoveButton();
    jQueryExample.RefreshButton();
    jQueryExample.ClearButton();
};</pre>
<p>Save and run the application.  Select the customer with the ID of one, then click the Remove Customer button.</p>
<p>If Fiddlers is running you should see the following address being sent to web api.</p>
<p><a href="http://localhost:60025/api/customer/1">http://localhost:60025/api/customer/1</a> with the verb of DELETE.</p>
<p>Upon completion that customer should disappear from the grid and if you check the database you will notice the Deleted column is not true.</p>
<p><img src="http://chadit.files.wordpress.com/2012/04/croppercapture66.png?w=640" alt="" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=290&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/04/16/chlodny-series-day-11-web-api-delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>

		<media:content url="http://chadit.files.wordpress.com/2012/04/croppercapture66.png" medium="image" />
	</item>
		<item>
		<title>Chlodny series Day 10: Clear selection</title>
		<link>http://researchaholic.com/2012/04/13/chlodny-series-day-10-clear-selection/</link>
		<comments>http://researchaholic.com/2012/04/13/chlodny-series-day-10-clear-selection/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=286</guid>
		<description><![CDATA[In session 9 we added paging and the selection events.&#160; If you selected one or more rows from the top grid it would populate the bottom grid.&#160; What if you want to remove everything from the selection grid Open up &#8230; <a href="http://researchaholic.com/2012/04/13/chlodny-series-day-10-clear-selection/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=286&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In session 9 we added paging and the selection events.&nbsp; If you selected one or more rows from the top grid it would populate the bottom grid.&nbsp; What if you want to remove everything from the selection grid</p>
<p><span id="more-286"></span>
<ul>
<li>Open up jQueryUILocal.htm
<li>Below our customers-selected table add a new div, we will give it a class name of tools.&nbsp; This will hold our button controls.
<li>Add a buttons for our clear selection</li>
</ul>
<pre class="csharpcode">&lt;div <span class="kwrd">class</span>=<span class="str">"tools"</span>&gt;
     &lt;button id=<span class="str">"clearSelection"</span>&gt;Clear selection&lt;/button&gt;
&lt;/div&gt;</pre>
<ul>
<li>Next open up jQueryUIExampleLocal.js
<li>Add a new function to bind it to the click event of the clear selection button</li>
</ul>
<pre class="csharpcode">jQueryExample.ClearButton = <span class="kwrd">function</span> () {
    $(<span class="str">"#clearSelection"</span>).click(<span class="kwrd">function</span> () {
        $.observable(selected).remove(0, selected.length);
        customers.refresh();
    });
};</pre>
<ul>
<li>What this function does it selects the selected object in the observable section of the dataviewer, removes all the rows in and then refreshes the customer dataviewer.
<li>The jQueryWireUp should not look like this.</li>
</ul>
<pre class="csharpcode">jQueryExample.jQueryWireUp = <span class="kwrd">function</span> () {
    jQueryExample.GetAllCustomer();
    jQueryExample.LoadDataView();
    jQueryExample.LoadDataGrid();
    jQueryExample.PageSizeOptions();
    jQueryExample.SelectedGridOptions();
    
    customers.refresh();

    jQueryExample.ClearButton();
};</pre>
<ul>
<li>Add some fields to the Customer selection and click the button ‘Clear selection’</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=286&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/04/13/chlodny-series-day-10-clear-selection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 9: Grid View enhance paging and selecting</title>
		<link>http://researchaholic.com/2012/04/11/chlodny-series-day-9-grid-view-enhance-paging-and-selecting/</link>
		<comments>http://researchaholic.com/2012/04/11/chlodny-series-day-9-grid-view-enhance-paging-and-selecting/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=279</guid>
		<description><![CDATA[In the last session we utilized AJAX and called into our Web API to get a list of all the customers in the Chinook database.  We then took those results and bound them to a data grid so that an &#8230; <a href="http://researchaholic.com/2012/04/11/chlodny-series-day-9-grid-view-enhance-paging-and-selecting/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=279&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In the last session we utilized AJAX and called into our Web API to get a list of all the customers in the Chinook database.  We then took those results and bound them to a data grid so that an end user can visually see those results.</p>
<p><span id="more-279"></span></p>
<p>In this session we will enhance the grid by allowing the end user to change the paging size.  We are going to setup a second grid so that when one or more rows are selected from the top grid they will show up in the bottom grid.</p>
<ul>
<li>First thing, open up jQueryUILocal.htm.</li>
<li>Go to the customers-local table</li>
<li>After the &lt;/tbody&gt; tag  at a &lt;tfoot&gt; tag (open and close)</li>
<li>Inside the table footer we will then add pager span, page size drop down and some row view information.  It should look similar to this</li>
</ul>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">tfoot</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                 <span class="kwrd">&lt;</span><span class="html">span</span> <span class="attr">id</span><span class="kwrd">="pager"</span><span class="kwrd">&gt;&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">label</span> <span class="attr">for</span><span class="kwrd">="pagesize"</span><span class="kwrd">&gt;</span>Pagesize<span class="kwrd">&lt;/</span><span class="html">label</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">select</span> <span class="attr">id</span><span class="kwrd">="pagesize"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">option</span><span class="kwrd">&gt;</span>10<span class="kwrd">&lt;/</span><span class="html">option</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">option</span><span class="kwrd">&gt;</span>20<span class="kwrd">&lt;/</span><span class="html">option</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span class="html">option</span><span class="kwrd">&gt;</span>30<span class="kwrd">&lt;/</span><span class="html">option</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span class="html">select</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">td</span><span class="kwrd">&gt;</span>
                Viewing rows <span class="kwrd">&lt;</span><span class="html">span</span> <span class="attr">class</span><span class="kwrd">="paging-from"</span><span class="kwrd">&gt;</span>0<span class="kwrd">&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span> to <span class="kwrd">&lt;</span><span class="html">span</span> <span class="attr">class</span><span class="kwrd">="paging-to"</span><span class="kwrd">&gt;</span>0<span class="kwrd">&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span> of <span class="kwrd">&lt;</span><span class="html">span</span> <span class="attr">class</span><span class="kwrd">="paging-total"</span><span class="kwrd">&gt;</span>0<span class="kwrd">&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">td</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">tfoot</span><span class="kwrd">&gt;</span></pre>
<p>Below the table (grid view) to show a separation we will add a break, line, break.  Then setup another table, for now we will make it identical (minus the paging information) and give it an id of ‘customers-selected</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">id</span><span class="kwrd">="customers-selected"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">caption</span><span class="kwrd">&gt;</span>Selected Customer<span class="kwrd">&lt;/</span><span class="html">caption</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">thead</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="CustomerId"</span><span class="kwrd">&gt;</span>ID<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="FirstName"</span><span class="kwrd">&gt;</span>First Name<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="LastName"</span><span class="kwrd">&gt;</span>Last Name<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Address"</span><span class="kwrd">&gt;</span>Address<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="City"</span><span class="kwrd">&gt;</span>City<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="PostalCode"</span><span class="kwrd">&gt;</span>PostalCode<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="State"</span><span class="kwrd">&gt;</span>State<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Country"</span><span class="kwrd">&gt;</span>Country<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Email"</span><span class="kwrd">&gt;</span>Email<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Phone"</span><span class="kwrd">&gt;</span>Phone<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Fax"</span><span class="kwrd">&gt;</span>Fax<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Company"</span><span class="kwrd">&gt;</span>Company<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">thead</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">tbody</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">tbody</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span></pre>
<p>To wire up the paging options create a new function named PageSizeOptions.  In this function we will do two things.  First we will bind our customers collection to the pager source.  This will give us that left, right, and page number functionality that we wall love. Secondly we will add a change event to the page size drop down.  This will allow the end users to change the page size from 10, 20, or 30 rows.  When the page size changes we will also call a refresh so that the grid can adjust for the change.  It should look like this:</p>
<pre class="csharpcode">jQueryExample.PageSizeOptions = <span class="kwrd">function</span>() {
    $(<span class="str">"#pager"</span>).pager({
        source: customers
    });

    $(<span class="str">"#pagesize"</span>).change(<span class="kwrd">function</span>() {
        customers.option(<span class="str">"paging.limit"</span>, +$(<span class="kwrd">this</span>).val()).refresh();
    });
};</pre>
<p>Next we will create a new function named SelectedGridOptions.  This function will bind the selected rows from ‘customers-local’ to the selected object and sets the source of the customers-selected grid to the selected object.  This function should look like this:</p>
<pre class="csharpcode">jQueryExample.SelectedGridOptions = <span class="kwrd">function</span>() {
    <span class="rem">// update status when selection changes</span>
    $.observable(selected).bind(<span class="str">"insert remove"</span>, <span class="kwrd">function</span>() {
        $(<span class="str">".selected-status"</span>).text(selected.length);
    });

    $(<span class="str">"#customers-selected"</span>).grid({
        source: selected
    });

    $(<span class="str">"#customers-local"</span>).grid({
        source: customers,
        heightStyle: <span class="str">"fill"</span>
    }).gridFilter().gridSort();
};</pre>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, &#8220;Courier New&#8221;, courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; }</p>
<p>Refresh <a href="http://localhost:60025/jQueryUILocal.htm" rel="nofollow">http://localhost:60025/jQueryUILocal.htm</a>, click and hold on customer 2 and drag to 7.  You should notice that as a new row is selected, the selected grid populates.  Do the opposite and you will see them disappear.</p>
<p><a href="http://chadit.files.wordpress.com/2012/04/croppercapture72.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="CropperCapture[72]" src="http://chadit.files.wordpress.com/2012/04/croppercapture72_thumb.png?w=681&#038;h=264" alt="CropperCapture[72]" width="681" height="264" border="0" /></a></p>
<p>Adjust the page size and use the page buttons to verify they all work.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/279/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/279/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=279&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/04/11/chlodny-series-day-9-grid-view-enhance-paging-and-selecting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>

		<media:content url="http://chadit.files.wordpress.com/2012/04/croppercapture72_thumb.png" medium="image">
			<media:title type="html">CropperCapture[72]</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 8: Display Web API GET in Grid View</title>
		<link>http://researchaholic.com/2012/04/09/chlodny-series-day-8-display-web-api-get-in-grid-view/</link>
		<comments>http://researchaholic.com/2012/04/09/chlodny-series-day-8-display-web-api-get-in-grid-view/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=275</guid>
		<description><![CDATA[For this session we are going to setup the JavaScript and HTML files to send a GET request to Web API and get a list of all the customers in the Chinook database, then we will display those in a &#8230; <a href="http://researchaholic.com/2012/04/09/chlodny-series-day-8-display-web-api-get-in-grid-view/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=275&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>For this session we are going to setup the JavaScript and HTML files to send a GET request to Web API and get a list of all the customers in the Chinook database, then we will display those in a grid.</p>
<p><span id="more-275"></span>
<p>First lets open up the jQueryUILocal.htm file </p>
<p>Between the body tags we want to add the following</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">h2</span><span class="kwrd">&gt;</span>jQuery UI Grid<span class="kwrd">&lt;/</span><span class="html">h2</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">table</span> <span class="attr">id</span><span class="kwrd">="customers-local"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">caption</span><span class="kwrd">&gt;</span>Customers Grid<span class="kwrd">&lt;/</span><span class="html">caption</span><span class="kwrd">&gt;</span>
   
    <span class="kwrd">&lt;</span><span class="html">thead</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">tr</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="CustomerId"</span><span class="kwrd">&gt;</span>ID<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="FirstName"</span><span class="kwrd">&gt;</span>First Name<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="LastName"</span><span class="kwrd">&gt;</span>Last Name<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Address"</span><span class="kwrd">&gt;</span>Address<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="City"</span><span class="kwrd">&gt;</span>City<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="PostalCode"</span><span class="kwrd">&gt;</span>Postal Code<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="State"</span><span class="kwrd">&gt;</span>State<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Country"</span><span class="kwrd">&gt;</span>Country<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Email"</span><span class="kwrd">&gt;</span>Email<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Phone"</span><span class="kwrd">&gt;</span>Phone<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Fax"</span><span class="kwrd">&gt;</span>Fax<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">th</span> <span class="attr">data-property</span><span class="kwrd">="Company"</span><span class="kwrd">&gt;</span>Company<span class="kwrd">&lt;/</span><span class="html">th</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">tr</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">thead</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">tbody</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">tbody</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">table</span><span class="kwrd">&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">type</span><span class="kwrd">="text/javascript"</span><span class="kwrd">&gt;</span>
        $(document).ready(<span class="kwrd">function</span> () {
            jQueryExample.jQueryWireUp();
        })
    <span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span></pre>
<p>In these examples we are hard coding the column names.&nbsp; For the jQuery UI Data grid it currently uses the tag &lt;thread&gt; to represent the column names.&nbsp; We utilize the data-property attribute to bind our json data field to the corresponding column name.&nbsp; For the value we can change the name to display something that is better for user experience.&nbsp; An example could be that instead of displaying CustomerId we can change it to be just ID.</p>
<p>Right before the closing body tab we are going to add some JavaScript that will call our soon to be created wire up function as soon as the document is ready.&nbsp; </p>
<p>Open up jQueryUIExampleLocal.js </p>
<p>We are going to create a few global objects to hold some data.&nbsp; At the top of the JavaScript file add the following:</p>
<pre class="csharpcode"><span class="kwrd">var</span> jQueryExample = {}; <span class="rem">// holds our functions</span>
<span class="kwrd">var</span> localCustomers;     <span class="rem">// used for the ajax calls and part of the dataview</span>
<span class="kwrd">var</span> customers;          <span class="rem">// used for the data view</span>
<span class="kwrd">var</span> selected = [];      <span class="rem">// used to hold which rows were selected.</span>
<span class="kwrd">var</span> grid;               // the datagrid</pre>
<p>Create a new function for our jQueryExample object named GetAllCustomers .&nbsp; It will look like this:</p>
<pre class="csharpcode">jQueryExample.GetAllCustomer = <span class="kwrd">function</span>() {
    $.ajax({
        dataType: <span class="str">"json"</span>,
        url: <span class="str">"http://localhost:60025/api/customer"</span>,
        async: <span class="kwrd">false</span>,
        success: <span class="kwrd">function</span> (result) {
            localCustomers = result;
        }
    });
};</pre>
<p>This function will use the jQuery ajax function to call our local Web API controller and return json. Adjust the port number to match what yours is.&nbsp; If this function executes successfully we take those results and save them to our global variable localCustomers.</p>
<p>Create another function that establishes our DataView object that will be utilized by the UI, name it LoadDataView.&nbsp; In the data view we are setting a default paging to 10.&nbsp; This can be changed at anytime which we will see in a later session.</p>
<pre class="csharpcode">jQueryExample.LoadDataView = <span class="kwrd">function</span>() {
    customers = $.ui.dataviewlocal({
        input: localCustomers,
        paging: {
            limit: 10
        }
    });
};</pre>
<p>Now we need a function that will allow us to manipulate the data grid.&nbsp; Create another function called LoadDataGrid.&nbsp; The function should look like this:</p>
<pre class="csharpcode">jQueryExample.LoadDataGrid = <span class="kwrd">function</span>() {
    grid = $(<span class="str">"#customers-local"</span>).grid({
        source: customers.result,
        refresh: <span class="kwrd">function</span>() {
            <span class="kwrd">var</span> paging = customers.options.paging,
                total = customers.totalCount;
            $(<span class="str">".paging-from"</span>).text(paging.offset + 1);
            <span class="kwrd">var</span> to = paging.offset + paging.limit + 1;
            <span class="kwrd">if</span> (to &gt; total) {
                to = total;
            }
            $(<span class="str">".paging-to"</span>).text(to);
            $(<span class="str">".paging-total"</span>).text(total);
        }
    });

    grid.gridSelectable({
        selected: selected
    });
};</pre>
<p>This function will select the grid ‘customes-local’ and save it to our grid global variable.&nbsp; In this function we are settings the source to the dataviewlocal customers.&nbsp; Setting up paging based off our default paging. </p>
<p>Finally we need to create the wire up function mentioned in the HTML section.&nbsp; Create a new function called jQueryWireUp.&nbsp;&nbsp; We will then call each of the functions that were just created above.&nbsp; It should look like this:</p>
<pre class="csharpcode">jQueryExample.jQueryWireUp = <span class="kwrd">function</span> () {
    jQueryExample.GetAllCustomer();
    jQueryExample.LoadDataView();
    jQueryExample.LoadDataGrid();
   
    customers.refresh();
};</pre>
<p>At the end we call customers.refresh();.&nbsp; This is a base function that jQuery UI has added to the dataviewlocal object.&nbsp; It tells the collection/grid to refresh and redisplay the data in the collection. </p>
<p>&nbsp;</p>
<p>Run the application and navigate to <a href="http://localhost:60025/jQueryUILocal.htm" rel="nofollow">http://localhost:60025/jQueryUILocal.htm</a> (adjust port number as needed).&nbsp; You should get a page that looks similar to the following:</p>
<p><a href="http://chadit.files.wordpress.com/2012/04/croppercapture71.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="CropperCapture[71]" border="0" alt="CropperCapture[71]" src="http://chadit.files.wordpress.com/2012/04/croppercapture71_thumb.png?w=638&#038;h=234" width="638" height="234"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/275/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/275/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=275&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/04/09/chlodny-series-day-8-display-web-api-get-in-grid-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>

		<media:content url="http://chadit.files.wordpress.com/2012/04/croppercapture71_thumb.png" medium="image">
			<media:title type="html">CropperCapture[71]</media:title>
		</media:content>
	</item>
		<item>
		<title>Chlodny series Day 7: Setup Client&#8211;CSS/jQuery UI Grid View</title>
		<link>http://researchaholic.com/2012/04/06/chlodny-series-day-7-setup-clientcssjquery-ui-grid-view/</link>
		<comments>http://researchaholic.com/2012/04/06/chlodny-series-day-7-setup-clientcssjquery-ui-grid-view/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 13:00:00 +0000</pubDate>
		<dc:creator>chadit</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[WebApi]]></category>

		<guid isPermaLink="false">https://chadit.wordpress.com/?p=271</guid>
		<description><![CDATA[Now that our database, Entity Framework, and Web Api are all setup lets give it a gui to play with.&#160; At a later data we will go over cross domain utilizing JSON with Passing or JSONP and Cross-Origin Resource Sharing &#8230; <a href="http://researchaholic.com/2012/04/06/chlodny-series-day-7-setup-clientcssjquery-ui-grid-view/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=271&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Now that our database, Entity Framework, and Web Api are all setup lets give it a gui to play with.&nbsp; At a later data we will go over cross domain utilizing JSON with Passing or JSONP and Cross-Origin Resource Sharing or CORS.&nbsp; For now we are going to demo a HTML and jQuery application on the same domain.&nbsp; The next few&nbsp; days we will spend time playing with the new alpha grid that the jQuery UI team is working on.&nbsp; The code is located <a href="https://github.com/jquery/jquery-ui/tree/grid">here.</a></p>
<p><span id="more-271"></span>
<ul>
<li>Add the following files to the project ChlodnyWebApi
<li>HTML page and name it jQueryUILocal.htm (to the main folder)
<li>JavaScript file and name is jQueryUIExampleLocal.js (to the scripts folder)</li>
</ul>
<p>Since we are using the jQuery UI Grid (alpha build) we need to use the jQuery UI files from that project, the released version do not contain the references to the grid scripts.</p>
<p>First lets build out the content folder for our CSS files</p>
<ul>
<li>Create a new folder under Content and name it jqueryGrid
<li>In jqueryGrid create a folder named themes
<li>In jqueryGrid create a new css file named jQueryUICssLocal.css
<li>In the themes folder add another folder with the name base
<li>Under base add the following CSS files from the alpha build
<ul>
<li>jquery.ui.accordion.css
<li>jquery.ui.all.css
<li>jquery.ui.autocomplete.css
<li>jquery.ui.base.css
<li>jquery.ui.button.css
<li>jquery.ui.core.css
<li>jquery.ui.datapicker.css
<li>jquery.ui.dialog.css
<li>jquery.ui.grid.css
<li>jquery.ui.menu.css
<li>jquery.ui.progressbar.css
<li>jquery.ui.resizable.css
<li>jquery.ui.selectable.css
<li>jquery.ui.slider.css
<li>jquery.ui.spinner.css
<li>jquery.ui.tabs.css
<li>jquery.ui.theme.css
<li>jquery.ui.tooltip.css</li>
</ul>
</li>
</ul>
<p>In the Scripts folder create a folder named jqueryGrid.<br />In that folder create another folder named ui.&nbsp; <br />Copy the following files from the project copied from link above to the ui folder</p>
<ul>
<li>jquery.ui.button.js
<li>jquery.ui.core.js
<li>jquery.ui.dataview.js
<li>jquery.ui.dataviewlocal.js
<li>jquery.ui.dialog.js
<li>jquery.ui.grid.js
<li>jquery.ui.menu.js
<li>jquery.ui.mouse.js
<li>jquery.ui.observable.js
<li>jquery.ui.position.js
<li>jquery.ui.selectable.js
<li>jquery.ui.spinner.js
<li>jquery.ui.tooltip.js
<li>jquery.ui.widget.js</li>
</ul>
<p>Copy the following files to the jqueryGrid folder</p>
<ul>
<li>dataview-odata.js
<li>globalize.js
<li>grid-filter.js
<li>grid-sort.js
<li>grid.selectable.js
<li>helpers.js
<li>jquery.mousewheel-3.0.4.js
<li>jquery.tmpl.js
<li>localstore.js
<li>navigator.js
<li>pager.js</li>
</ul>
<p>Open the jqueryUILocal.htm we need to add our CSS and JS files to the file.&nbsp; (before I get hate mail… please note that this is for demo purposes only, I know that some of these ways go against web standards and there are better/proper ways of doing things.)</p>
<p>You can either type in all the files needed or from solution explorer drag and drop them into the htm page.&nbsp; Add CSS and jquery first.&nbsp; After completed it should look similar to the following:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">head</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;</span>jQuery BABY (Local) !!!!<span class="kwrd">&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">link</span> <span class="attr">href</span><span class="kwrd">="Content/jqueryGrid/themes/base/jquery.ui.all.css"</span> <span class="attr">rel</span><span class="kwrd">="stylesheet"</span> <span class="attr">type</span><span class="kwrd">="text/css"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">link</span> <span class="attr">href</span><span class="kwrd">="Content/jqueryGrid/jQueryUICssLocal.css"</span> <span class="attr">rel</span><span class="kwrd">="stylesheet"</span> <span class="attr">type</span><span class="kwrd">="text/css"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">src</span><span class="kwrd">="Scripts/jquery-1.7.1.js"</span> <span class="attr">type</span><span class="kwrd">="text/javascript"</span><span class="kwrd">&gt;&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
    &lt;script src=<span class="str">"Scripts/jqueryGrid/globalize.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/jquery.tmpl.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/jquery.mousewheel-3.0.4.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.core.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.widget.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.button.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.spinner.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.tooltip.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.menu.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.position.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.dialog.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.mouse.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.selectable.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.observable.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;    
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.dataview.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.dataviewlocal.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt; 
    &lt;script src=<span class="str">"Scripts/jqueryGrid/ui/jquery.ui.grid.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/dataview-odata.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/pager.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/grid-filter.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/grid-sort.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/grid.selectable.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/navigator.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/localstore.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jqueryGrid/helpers.js"</span> type=<span class="str">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script src=<span class="str">"Scripts/jQueryUIExampleLocal.js"</span> type=<span class="str">"text/javascript"</span>&gt;<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chadit.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chadit.wordpress.com/271/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=researchaholic.com&#038;blog=10560698&#038;post=271&#038;subd=chadit&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://researchaholic.com/2012/04/06/chlodny-series-day-7-setup-clientcssjquery-ui-grid-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/b036dc291165d1f8d77299b9599d8250?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">chadit</media:title>
		</media:content>
	</item>
	</channel>
</rss>
