<?xml version="1.0" encoding="iso-8859-1"?>
<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/"
	>

<channel>
	<title>Pure-Essence.Net &#187; paginator</title>
	<atom:link href="http://pure-essence.net/tag/paginator/feed/" rel="self" type="application/rss+xml" />
	<link>http://pure-essence.net</link>
	<description>you must visit this geeky girl&#039;s weblog!</description>
	<lastBuildDate>Fri, 12 Mar 2010 20:22:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Why I prefer jQuery over YUI</title>
		<link>http://pure-essence.net/2008/10/11/why-i-prefer-jquery-over-yui/</link>
		<comments>http://pure-essence.net/2008/10/11/why-i-prefer-jquery-over-yui/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 14:16:26 +0000</pubDate>
		<dc:creator>dodo</dc:creator>
				<category><![CDATA[geeky]]></category>
		<category><![CDATA[non php code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[datatable]]></category>
		<category><![CDATA[date picker]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[paginator]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://pure-essence.net/?p=1327</guid>
		<description><![CDATA[While at work, I was trying to find a way to easily do server side pagination without writing all the lovely logic myself. Due to some constraints, I am unable to use more high end framework such as JSF and struts. Which in a way I believe is a good thing. I would have more [...]]]></description>
			<content:encoded><![CDATA[<p>While at work, I was trying to find a way to easily do server side pagination without writing all the lovely logic myself. Due to some constraints, I am unable to use more high end framework such as JSF and struts. Which in a way I believe is a good thing. I would have more control over just writing servlets. However, having written pagination logic before, I really did not want to write that again. Somehow I thought of jQuery. Just for amusement, I looked for <a href="http://jquery.com/">jQuery</a> pagination plugin and guess what <a href="http://plugins.jquery.com/project/pagination">I found it</a>! By using this plugin, I can pass in some simple parameters such as total records, records per page, number of pages shown etc. to have jQuery generate a paginator for me. That&#8217;s beyond cool so I put it into action.</p>
<p><a href="http://regretless.com/work/eAdjusterActivityReport/uploadReport.php">Upload Report Mock</a> uses the jQuery pagination plugin but handles the pagination on the server side via php.</p>
<p>Ultimately what I also want to handle is the following scenario:</p>
<ul>
<li> I have a table of data, one of the column is editable.</li>
<li> If the user clicks on the column of a particular table row, a modal window will pop up asking for additional information.</li>
<li> The user fills out the information and submits.</li>
<li> The window updates the info for that table via AJAX and updates the results screen</li>
</ul>
<p>While I was eager for figure out how to accomplish that in jQuery, I found out that it is not one of the previously used javascript framework at work so they asked if I could look into <a href="http://developer.yahoo.com/yui/">YUI</a>.</p>
<p>Digging into YUI, first I tried to accomplish the same thing using the <a href="http://developer.yahoo.com/yui/paginator/">YUI paginator widget</a>. I spent two hours but it really does not seem like I can generate some href tags with this component like I could with the jQuery plugin. With jQuery, I could produce:<br />
<code>&lt;div id="pagination"&gt;
&lt;a class="prev" href="/work/eAdjusterActivityReport/uploadReport.php?page=1"&gt;Prev&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=1"&gt;1&lt;/a&gt;
&lt;span class="current"&gt;2&lt;/span&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=3"&gt;3&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=4"&gt;4&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=5"&gt;5&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=6"&gt;6&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=7"&gt;7&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=8"&gt;8&lt;/a&gt;
&lt;span&gt;...&lt;/span&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=10"&gt;10&lt;/a&gt;
&lt;a href="/work/eAdjusterActivityReport/uploadReport.php?page=11"&gt;11&lt;/a&gt;
&lt;a class="next" href="/work/eAdjusterActivityReport/uploadReport.php?page=3"&gt;Next&lt;/a&gt;
&lt;/div&gt;</code><br />
With YUI, I have to hook up the paginator with another javascript or YUI widget. So to make things easier, I looked into <a href="http://developer.yahoo.com/yui/datatable/">YUI&#8217;s datatable component</a> and found <a href="http://developer.yahoo.com/yui/examples/datatable/dt_dynamicdata.html">an example to use it with server side pagination and sorting</a>. That seems to accomplish the overall need of pagination. Although that&#8217;s a bit of overkill but I thought it&#8217;s worth a shot. I spent 8 hours implementing it via server side JSON. Here&#8217;s what I produced:<br />
<a href="http://regretless.com/work/eAdjusterActivityReport/uploadReportYUI.php">Upload Report Mock with YUI</a></p>
<p>Instead of 10 lines of javascript code <a href="http://regretless.com/work/eAdjusterActivityReport/uploadReport.php">like the previous</a>, this one has 68 lines. But it does provide AJAX pagination so I thought that&#8217;s mostly fair.</p>
<p>Next I looked for a simple date picker calendar in YUI like <a href="http://marcgrabanski.com/pages/code/jquery-ui-datepicker">the jQuery date picker plugin</a>. The date picker is a necessary functionality of the application. With jQuery, it&#8217;s extremely easy to use. You add the plugin js &amp; css links, and then you give your input css class or unique IDs and with jQuery selector, just call the plugin via:<code>$("#startDate").datepicker()</code></p>
<p>Click on the start and end dates in <a href="http://regretless.com/work/eAdjusterActivityReport/uploadReport.php">Upload Report Mock</a> to see it in action.</p>
<p>Using YUI, I looked into its calendar component.  The closest thing I could find is <a href="http://developer.yahoo.com/yui/examples/calendar/calcontainer.html">this example</a>.</p>
<p>Not only would it need all these extra js includes<br />
<code>&lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/event/event-min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/dragdrop/dragdrop-min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/element/element-beta-min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/button/button-min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/container/container-min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/calendar/calendar-min.js"&gt;&lt;/script&gt;</code><br />
It also requires another <a href="http://regretless.com/work/eAdjusterActivityReport/YUICalendarCode.txt">76 lines of javascript code</a> for just adding one date picker.</p>
<p>Despite the complication, I tried to make it work with <a href="http://regretless.com/work/eAdjusterActivityReport/uploadReportYUI.php">my Upload Report Mock with YUI</a> but I failed pretty miserably. Sure if I put in enough hours, I will eventually make it work but WHY? Why would you stop yourself from using something else that takes 2 seconds?</p>
<p>At this point, I presented my findings to my co-workers. I really hope they will accept jQuery. Yea sure it&#8217;s yet another new javascript framework but it will save coding time.</p>
<p>Here&#8217;s another comparison. I found a very <a href="http://www.webplicity.net/flexigrid/">YUI datatable like jQuery plugin flexigrid</a>. Take a look at example 3. Lines of code to use server side pagination and sorting: 33.  In <a href="http://regretless.com/work/eAdjusterActivityReport/uploadReportYUI.php">my Upload Report Mock with YUI</a>, <a href="http://regretless.com/work/eAdjusterActivityReport/YUIDataTableCode.txt">I used 68 lines</a>. Also let&#8217;s do a comparison to see which one makes more sense and is less verbose.</p>
<p>jQuery:<br />
<code>$("#flex1").flexigrid({
	url: 'post2.php',
	dataType: 'json',
	colModel : [
		{display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'},
		{display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'},
		{display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'},
		{display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true},
		{display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'}
		],
	buttons : [
		{name: 'Add', bclass: 'add', onpress : test},
		{name: 'Delete', bclass: 'delete', onpress : test},
		{separator: true}
		],
	searchitems : [
		{display: 'ISO', name : 'iso'},
		{display: 'Name', name : 'name', isdefault: true}
		],
	sortname: "iso",
	sortorder: "asc",
	usepager: true,
	title: 'Countries',
	useRp: true,
	rp: 15,
	showTableToggleBtn: true,
	width: 700,
	height: 200
	}
);</code></p>
<p>YUI: <a href="http://regretless.com/work/eAdjusterActivityReport/YUIDataTableCode.txt">click for source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://pure-essence.net/2008/10/11/why-i-prefer-jquery-over-yui/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
