<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.23517-</id>
  <updated>2009-11-05T20:05:27Z</updated>
  <title>Comments for YUI DataTable Component (http://www.insideria.com/2008/06/yui-datatable-component-1.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.23517</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=23517" title="YUI DataTable Component" />
    <published>2008-06-29T16:00:00Z</published>
    <updated>2008-07-28T20:29:10Z</updated>
    <title>YUI DataTable Component</title>
    <summary>The DataTable component allows us to display and manipulate tabular
data.  It can be used to enhance an existing HTML table, produce one based on data fetched from a remote
data source in JSON, XML or CSV format or a local (client side) source in a few
more formats. 

</summary>
    <author>
      <name>Daniel Barreiro</name>
      
    </author>
    
    <category term="Features" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<div class="ap_r" style="margin: 16px;"><a href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/yuidata.jpg" class="highslide" onclick="return hs.expand(this)"><img src="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/yuidata.jpg" alt="yuidata.jpg" title="Click to enlarge" width="148"/></a></div>The <a target="_blank" href="http://developer.yahoo.com/yui/datatable/">DataTable</a> component allows us to display and manipulate tabular
data.  It can be used to enhance an existing HTML table, produce one based on data fetched from a remote
data source in <a target="_blank" href="http://www.json.org/">JSON</a>, XML or CSV format or a local (client side) source in a few
more formats.  The
first option is handy when you don't want to completely redo the server side
portion of an existing application which is already generating the HTML table
and you want to enhance the UI or when
you want to provide for users who might not have JavaScript enabled, so that they
at least get a regular HTML table.
<p>The DataTable has methods to add and delete rows and columns, to sort,
resize, show, hide and move columns around, to edit cells in place with plain
(textbox or textarea), enhanced (using the Calendar component for dates) or
custom editors.  In all, the DataTable has many of the UI features of a
regular spreadsheet and it is often confused with one.  A spreadsheet,
though, allows you to put any type of data in any cell, there is a block of
meta-data associated with each individual cell, the DataTable has meta-data
associated with each column, just as with a database table.</p>
<p>In a <a href="http://www.insideria.com/2008/06/the-yahoo-user-interface-libra-1.html">previous article</a>  I wrote about how to get started with the YUI, how to load
the libraries and find whether the DOM was loaded and stable before trying to
do anything with it.  We also saw how to hide your variables from
the global scope so that you didn't have to get concerned with name
collision.  In the sample code, there was a comment saying 'Your code
here', we will see what your code could be for a DataTable.</p>
<strong>The Data Source</strong><br/>
<p>The DataTable fetches data through the <a target="_blank" href="http://developer.yahoo.com/yui/datasource/">DataSource</a> component, which is the one
that contains all the parsers for the different types of data formats supported.  The DataSource component is the same one used by the
<a target="_blank" href="http://developer.yahoo.com/yui/charts/">Charts</a>
component (the <a target="_blank" href="http://developer.yahoo.com/yui/autocomplete/">AutoComplete</a> component
still uses an earlier incompatible version of DataSource).  The DataSource produces
an array with all the requested data for the DataTable.  A few definitions
allows the DataSource to fetch the data, extract its fields and parse the
values.</p>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> myDataSource = <span class="category1">new</span> YAHOO.util.DataSource('<span class="quote">json_proxy.php?</span>', {
     responseType: YAHOO.util.DataSource.TYPE_JSON,
     responseSchema: {
           resultsList: '<span class="quote">data</span>',
           fields: [
               {key: '<span class="quote">id</span>', parser: YAHOO.util.DataSource.parseNumber},
               '<span class="quote">name</span>',
               {key: '<span class="quote">date</span>', parser: YAHOO.util.DataSource.parseDate}
           ]
      }
});</pre>
</code>

</div></div> 

<p>The code above would create a DataSource instance which will retrieve data
remotely from the URL given in the first argument, it will expect the data to be
in JSON format and the array of records under a property called <code>data</code>. 
It will then extract three fields, <code>id</code>, <code>name</code> and <code>date</code>. 
For data formats, such as plain text, where there are no field names, the field
values will
be read in the order given.</p>
<p>The <code>name</code>  field,
being a plain string, doesn't need any parser and you can simply give the name
of the field. The first one needs to be parsed as a number, the last as a date so you have to
tell which parser to use.  The DataSource includes parsers for several
kinds of data but you can also provide your own.  A parser simply receives
the value as it came in the data packet (usually a string) and should return it
converted to whatever the closest native JavaScript type is. Though
JavaScript can do automatic type conversion it not always does so.  It
often happens when asking the DataTable to sort a column, that a 12 will end up
sorted before a 2 because the parser was missing and it compared them as strings
not numbers.</p>
<p>Since the DataSource is able to fetch data asynchronously, once it is set up,
you call the <code>sendRequest</code> method and give it, amongst other things, the
callback function that will receive the data when it finally arrives and gets
processed. If used with the DataTable, you just pass the
DataSource instance already set up to the DataTable and it will do it for you.  The
DataTable will store the data received in its <code> RecordSet</code> object.  You can fetch more or
less fields than you will show.  Some extra fields might be for internal
use and you don't want them shown; some extra columns may be made up, usually UI
elements such as buttons or checkboxes.</p>
<strong>The Columns Definition</strong><br/>
<p>The next thing we need to do is to define which columns will be shown. 
We do that through an array usually called the columns definitions. The
array contains one entry per visible column. Each column definition is an object
literal with several properties.  Only one is required, the <code>key</code>,
which is the name by which this column will be recognized.  The value of
the <code>key</code> property in the column definition must match the value of the <code>key</code>
property in the <code> fields</code> definition of the DataSource.</p>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre>
<span class="category1">var</span> myColumnDefs = [
    {key: '<span class="quote">id</span>'},
    {key: '<span class="quote">name</span>', <span class="category1">label</span>: '<span class="quote">User Name</span>'},
    {key: '<span class="quote">date</span>', <span class="category1">label</span>: '<span class="quote">Last Login</span>', formatter: '<span class="quote">date</span>'}
];</pre>
</code>

</div></div> 

<p>Here is a possible columns definition for the previous set of data.  We
will show all three fields, we change the column headers of the last two,
otherwise it defaults to the <code>key</code> value, and we further specify that the
last one should be formatted as a date.  The <code>formatter</code> property can
be either a string, as in this case, or a function.  If a string, it should
correspond to one of the named built-in formatters, if a function the DataTable
will call it for each cell, passing it the value to be formatted, the DOM
reference to the cell where it will be displayed and references to the <code>Record</code>
and <code>Column</code> objects where it belongs.  The formatter can thus access
other fields in the same <code>Record</code> to decide how to format it (even hidden
fields) or extra info in the <code>Column</code>.  You are free to add your own
properties to the columns definition, the DataTable will preserve those which
can later be used, for example, in your custom formatter.</p>
<p>Since the formatter has access to the HTML cell, it can not only set its
contents with the formatted value but can also change its style. For example,
setting right alignment or changing colors, or it can also draw HTML elements
such as links, buttons or image tags.</p>
<p>You can also define columns with no associated data field in the <code>RecordSet</code>. 
You will still give them a unique <code>key</code> name and you will have to provide a <code>formatter</code>
otherwise it will simply show an empty cell.</p>
<p>There are many other column options such as <code>sortable</code>, <code>resizeable</code>,
<code>width</code> or <code>minWidth</code> which are self-explanatory. You can also assign an <code>editor</code> to any
column.  Just like with <code>formatter</code>, you can use a named built-in
editor or you can define your own.  This is somewhat more involved than custom formatters so I won't cover it here.  There are plain text editors (both
textbox and textarea), calendars, dropdowns, multi-option checkboxes or radio
buttons.  You can provide extra options for some of these with the <code>editorOptions</code>
property. </p>
<p>  You can override the built-in column sorter with the <code>sortOptions</code>
property and you can give a column a particular style with the <code>className</code>
property.</p>
<p>The <code>hidden</code> property will render the column as hidden.  This is
different from not naming the column in the columns definition.  When you
don't name it, the column will never exist, when you do define it as <code>hidden</code>,
it will render collapsed, just a narrow vertical strip, which can be shown at
any time via the <code>showColumn</code> method.</p>
<p>Finally, columns can be nested.  Any given column can have a <code>children</code>
property which can contain a further array with the nested columns
definition.</p>
<strong>Creating the DataTable</strong><br/>
<p>We are now ready to create the DataTable instance.</p>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;">
<code language="perl">
<pre> 
<span class="category1">var</span> myDataTable = <span class="category1">new</span> YAHOO.widget.DataTable('<span class="quote">tableContainer</span>', 
	myColumnDefs, myDataSource, myOptions);</pre>
</code>

</div></div> 
<p>This will create and render the DataTable.  The first argument should be
a reference to an existing DOM object which will hold the DataTable or, as in
this example, the value of the <code>id</code> attribute of an HTML element.  We then
provide the references to the columns definition and the DataSource object. 
These three are mandatory arguments: where to put it, what to put there and
where to get it from. There is a fourth optional argument, an object with several configuration attributes for the whole
DataTable.  This is a common practice across the YUI library, the
constructors of most complex components can accept a last optional argument
which is an object literal to set multiple optional attributes at once. 
Usually they can also be set by other means, but it is often handy to do it all
at once. We'll see those options in the next section, in the meantime, if you
want to see it at work, you can check a couple of examples.  </p>
<p>The <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample1.html">first one</a> uses an existing table as the basis
to build an active DataTable.  If you turn JavaScript off, you can still
see the plain HTML table, completely undecorated and passive (actually,
depending on the speed of your connection you might get to see it briefly before
it is replaced).  Admittedly, making it more palatable only involves
setting a few styles. I don't mean to imply that without JavaScript decent
tables cannot be built, but it is nevertheless true that if you mean to support users with and without JavaScript enabled, the visual design has
to be duplicated to suit both situations, with the non-JavaScript alternative
further complicated by all the extra elements (forms, buttons, links and such)
that need to be added to get from the server the functionality that the YUI
library provides on the client side.  The CSS components of the YUI library
can still be used in this situation so a little help could still be had.</p>
<p>The <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample2.html">second example</a> does require JavaScript to be
active and uses a server providing data in JSON format.  There is little
HTML that needs to be provided for the active components, in this case a single
container to draw the table in.  I have been further skimpy in the use of
variables. I didn't store the DataSource and columns definitions in separate
variables but defined them in-line.  Examples usually avoid this, as I did
in the <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample1.html">previous example</a>, in order to guide the reader
step by step, so I went the opposite way in <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample2.html">this example</a>
to even things out.  Both examples are well commented. </p>
<p>Variables explicitly declared within a function are local to that function
and thus invisible from outside that function.  We have used that feature
of JavaScript in both examples.  By the time I am declaring the DataTable,
the variable <code>dt</code> is local to a function nested three levels deep from the
global namespace.  There is no chance that any variable that I explicitly
declare inside it would ever clutter the global namespace.  Variables used
without explicitly declaring them first do go to the global namespace, that is
why I have already repeated 'explicitly' three times in this paragraph: please
do use <code>var</code>.  This is important when working in large projects with
code provided by your colleagues or third party libraries: don't clutter the
global namespace.</p>
<p>There is, however, the need to share components on the page.  We do that
in <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample2.html">this example</a> by copying the reference to the
DataTable we have just created from the local variable <code>dt</code> to <code>YAHOO.example.myDataTable</code>.
As I mentioned in the a <a href="http://www.insideria.com/2008/06/the-yahoo-user-interface-libra-1.html">previous article</a>, all the YUI
library is stored inside variable <code>YAHOO</code>, which is further subdivided in
several sections, <code>widget</code>, <code>lang</code>, <code>util</code> and a few
others.  These are no more than properties in the <code>YAHOO</code> object
containing further objects.  One of those, <code>example</code>, is already
created and available for anybody to use.  This one does not need to be
declared, explicitly or not, YUI already has declared it, you can simply use it
as we did here, by assigning to previously non-existent property <code>myDataTable</code>
the reference to the new DataTable.  Any other code in the same page will
be able to access this DataTable by using its full name, <code>YAHOO.example.myDataTable</code>.</p>
<p>We could have used the full name all along instead of <code>dt</code>.  
There are several advantages to <b>not</b> do so.  First, it is shorter to write and I do value my time.  
Second, it may be faster for the interpreter. The extra time needed to create that extra <code>dt</code> variable
compensates the time it would take the interpreter to solve <code>YAHOO</code> then <code>example</code> and finally <code>myDataTable</code> several times. 
Finally, the YUI Compressor can safely replace the <code>dt</code> or any other possibly longer name 
with a shorter made-up name since it knows it is local to that function, something it cannot do with the full name.</p>
<p>The <code>YAHOO.example</code> namespace should be used with caution.  If you
are building libraries, you should define, keep a record of and manage your own
namespace as I've shown in the a <a href="http://www.insideria.com/2008/06/the-yahoo-user-interface-libra-1.html">previous article</a>, 
but for code that fits into a single page and will never be included inside
other pages, it is a handy place to put things.</p>
<strong>DataTable Options</strong><br/>
<p>The <code>caption</code> and <code>summary</code> attributes will be copied to the corresponding HTML
tags.  If the data comes already sorted, you can let the DataTable know via
the <code>sortedBy</code> attribute so that it will highlight the corresponding column. This
attribute does not force a sort on the DataTable, it simply tells it when the
data comes already sorted. The <code>selectionMode</code> attribute lets you specify whether the user can select by row,
cell range or cell block and whether it can be single or multiple item selection. 
If the <code>draggableColumns</code> attribute is set, the columns can be reordered by
dragging them with the mouse into their new positions.</p>
<p>When we created <code>myDataSource</code>, we cut the URL at the question
mark.  We don't specify the full request because the DataTable might be
paginated or associated to a search box to filter records and each might require
different URL arguments. We set the DataSource
to the base URL of the server so we can reuse it for all requests.  We set
the initial arguments for the request through the <code>initialRequest</code>
attribute.</p>
<p>Normally the DataTable will draw an HTML table which will adjust itself
according to its style, the available space and its contents, as normal HTML
tables do.  The <code>scrollable</code> attribute will let you specify a <code>width</code> and <code>height</code> for it and will
produce a couple of scrollbars so that the table contents will scroll but will
leave the headers always visible.</p>
<p>If the data set is long, there are several alternatives to speed up the
rendering.  The <code>renderLoopSize</code> attribute tells the DataTable to yield its
thread to the browser every several rows thus unfreezing the UI.  Though in
the end the DataTable will take longer to render, due to this yielding and
resuming, the user will perceive it as faster since it will start seeing some
results almost immediately and the interface will remain responsive.</p>
<p>The DataTable also supports pagination, both on the client and on the server
side.  You enable it by setting the <code>paginator</code> attribute to an instance of
the <code>Paginator</code> object (or one you provide) which takes several attributes, all
optional and with suitable defaults, such as page size, initial page, location
of the page navigation controls or a template for those controls with
placeholders for each element.</p>
<p>Client-side pagination can be used for styling, ie. you might not want your
DataTable to stretch forever.  Sometimes, the time to render the DataTable,
specially with complex formatters can be quite long.  Client-side
pagination allows you to render a page at a time, which can make the UI more
responsive.  It might also avoid the warning that some browsers provide
when a script is taking too long to finish. </p>
<p>For really long data sets you need server-side pagination.  This
requires you to change the <code>paginationEventHandler</code>
attribute from the default client-side handler to the built-in server-side
handler or one you provide.   The built-in handler keeps a page cache
so that when the user returns to a previously seen page, it will not generate a
new request.  You can also change the <code>generateRequest</code>
method from the default to one of your own which will build the URL search
argument (the part after the question mark) to suit your server.  This
will replace the one given in the <code>initialRequest</code> attribute.</p>
<strong>Events</strong><br/>
<p>The DataTable provides a large set of custom events which you can subscribe
to.  These are handled through the <code>YAHOO.util.Event</code> component of YUI.  
The DataTable uses event delegation extensively so that you can respond to, lets
say, click events on all or any cells in a DataTable without setting an event
listener for each actual cell, which would take huge amounts of memory. 
The DataTable listens to clicks at the HTML table level and then, according to
the target, it fires its own custom event providing arguments far more suitable
for manipulating the DataTable  than the raw DOM event could.</p>
<p>Most significant moments in the DataTable trigger events of one kind or
another, some of them originating in the DOM (all sorts of clicks at every
level, keystrokes or mouse movements) others produced by the DataTable itself,
such as when the table is rendered, a column is sorted or a row selected.</p>
<p>The DataTable also has built-in methods which you can use as event listeners,
some of them already assigned, such as sorting a column for clicks on column
headers, others which you can choose from such as either popping up the in-line cell editor
for clicks on cells or do cell selection or even do both.  In the examples (<a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample1.html">1</a>,
<a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample2.html">2</a>) we have assigned the method that pops up the
in-line cell editor (<code>onEventShowCellEditor</code>) to cell clicks (<code>cellClickEvent</code>). 
Right after doing so, we subscribe to that same event the <code>onEventSelectRow</code>
listener. 
More than one listener can be assigned to the same event and each will be called
in turn in the order they were assigned.  </p>
<p>Notice, though, that event listeners cannot consume the event.  The cell
editor listener first checks if the cell clicked is in a column with an editor
assigned, if not, it ignores it.  However, the select row event is called
either way so in <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample1.html">example 1</a>, clicking on the cells of
the two right-most columns will make both the editor pop up and the row to get
selected. This side effect might not be what you want.   We fixed that
in the <a target="_blank" href="http://www.insideria.com/upload/2008/04/yui_datatable_component_1/sample2.html">example 2</a>.   Basically, what we do
there is the opposite of what <code>onEventShowCellEditor</code> does internally,
first we find the column where the click happened and, if it doesn't have an
editor assigned, we call <code>onEventSelectRow</code>.  A couple of things to
notice.  If you listen to an event triggered by the DataTable, the scope of
the listener will be set to that of the object that triggered the event, ie, the
DataTable.  Second, the single argument to that listener is an object which
will have properties suitable to manipulate the YUI object which makes it easy
to find the column as we do in the example.</p>
<p>You can also capture other interesting moments by overriding some existing
basically do-nothing methods.</p>
<p>As a general rule, for the whole of the YUI library, methods starting with
the prefix <code>on</code> and more precisely <code>onEvent</code> are event listeners
either already set or available for you to assign to events of your choice, such
as <code>onEventShowCellEditor</code>.  Methods starting with the prefix <code>do</code>
(quite often <code>doBefore</code> or <code>doAfter</code> something) are usually
overridable methods.  Of course, JavaScript will allow you to override any
method and YUI can't prevent you from doing so. Why should it?</p>
<strong>In-line Cell Editing</strong><br/>
<p>There are two ways you can modify the DataTable, you can set the <code>editor</code>
property in the columns definition to one of the built-in editors or a custom
one you provide.  This will make an editor pop up right on top of the cell
being edited.  You can have single or multi-line text editors,
multi-options (several checkboxes or radio buttons for a single cell), dropdowns
or full calendars (using <code><a target="_blank" href="http://developer.yahoo.com/yui/calendar/">YAHOO.widget.Calendar</a></code>).  Each pop up editor
has Ok/Cancel buttons on it.  You can assign a <code>validator</code> function in
the <code>editorOptions</code> property of the columns definition to do an
initial check on the entered value.</p>
<p>The other way is by drawing active HTML controls such as checkboxes, radio
buttons or dropdown boxes via the built-in or your custom formatters.  You
respond to these controls through the corresponding DataTable events.  Of
course you can handle these events by listening to the raw DOM event, but the
DataTable event will provide you with far more useful arguments specifically
related to the DataTable, such as the cell reference or the <code>Record</code> and <code>Column</code>
objects.   While the in-line editors directly modify the underlying <code>RecordSet</code>
object, where the data is actually stored, none of these do so because some of
these controls might not be meant to actually edit data but to trigger other
actions so, if you mean them to edit data, you are responsible to change the <code>RecordSet</code>
which is easy enough with the arguments provided to the event listener.</p>
<p>The changes to the <code>RecordSet</code> do not get sent to the server. 
Since there is no standard way to communicate and trigger transactions on
a  server, the DataTable only provides plenty of events and overridable
functions to let the programmer know when a change happens and then send those
changes to the server in whichever way the server expects them.  Lots of
people initially believe that by setting the DataSource, a two way communication
is set.  The DataSource can only fetch data not send if back to the
server.  All the options that would be needed to specify how to communicate
changes to the server, whether to use HTTP GET, POST or PUT requests, URL, XML
or JSON-encoding, data conversion and how to receive confirmation, rejection or
error information back and what to do with it, would make such a two way
communications component big, cumbersome and tedious to set up.   The
DataTable provides the developer with the hooks to make it, possibly using the <a target="_blank" href="http://developer.yahoo.com/yui/connection/">
Connection Manager</a> component for asynchronous communication or <a target="_blank" href="http://developer.yahoo.com/yui/get/">Get</a>
component which allows you to asynchronously fetch data from other domains.</p>
<p>The DataTable provides no means to put it on hold until the server
confirmation is received.  The changes are immediately reflected on the
UI.  If the server rejects a change or replies with an error, it is up to the developer to
revert the change.  Though this is in line with the philosophy of providing
a responsive, non-blocking UI, it is somewhat dangerous because the user will
see the change in the screen and might focus elsewhere on the page or even
navigate away from it trusting the change has been made in the server, failing
or unable to see the rejection from the server.</p>
<strong>Integration with other Components</strong><br/>
<p>Further interaction with the DataTable can be provided by the pop up <code>ContextMenu</code>
of the <a target="_blank" href="http://developer.yahoo.com/yui/menu/">Menu</a> component, often assigned to right clicks on cells or rows. Record
filtering can be done via the search box of the <a target="_blank" href="http://developer.yahoo.com/yui/autocomplete/">AutoComplete</a> component. 
The <a target="_blank" href="http://developer.yahoo.com/yui/history/">Browser History Manager</a> component can be used along the native Paginator so
that the paging through the DataTable gets reflected in the browser so you can
go back to previously visited pages with the browser back button or history drop
down.  As mentioned, if the <a target="_blank" href="http://developer.yahoo.com/yui/calendar/">Calendar</a> component is included, the in-line
editor for dates will use it automatically.  Column resizing and dragging
depends on the <a target="_blank" href="http://developer.yahoo.com/yui/dragdrop/">Drag and Drop</a> component.   The same data shown in
tabular form with the DataTable can be displayed graphically with the <a target="_blank" href="http://developer.yahoo.com/yui/charts/">Charts</a>
component, both use the DataSource to fetch information.</p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2019277</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2019277" />
    <title>Comment from Jim on 2008-07-25</title>
    <author>
        <name>Jim</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>thanks for the article, i've been using the DataTable for a few things but i'd like to use it more including the inline-editing features. (I think i'll use smaller buttons for ok and cancel though)<br />
jim</p>]]>
    </content>
    <published>2008-07-25T20:37:07Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2042025</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2042025" />
    <title>Comment from Palani on 2008-08-29</title>
    <author>
        <name>Palani</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Is it possible to add the additional rows below of each rows while page rendering itself?</p>]]>
    </content>
    <published>2008-08-29T13:02:44Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2042027</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2042027" />
    <title>Comment from Satyam on 2008-08-29</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Palani,</p>

<p>The feature is not supported by the DataTable itself. </p>

<p>It is possible to do so and some people have done it, but it is quite involved since many of the dynamic features of the DataTable mean the whole table might be rearranged by sorting columns, paging, column resizing or reordering. </p>

<p>Added rows might get wiped out by any such redrawing and your added rows might interfere with it.  </p>

<p>This said, it can be done and it has been done, but much care is required.</p>

<p><br />
</p>]]>
    </content>
    <published>2008-08-29T13:48:32Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2046028</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2046028" />
    <title>Comment from Anonymous on 2008-11-10</title>
    <author>
        <name>Anonymous</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Thanks for this article.</p>]]>
    </content>
    <published>2008-11-10T18:50:42Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2052395</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2052395" />
    <title>Comment from Patrick on 2009-02-06</title>
    <author>
        <name>Patrick</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>is there any quick way to get all of the data from the datatable, after rows have been added/deleted, in JSON?</p>

<p>I've tried datatable.getDataSource().liveData but that does not seem to be updated or what I want.</p>]]>
    </content>
    <published>2009-02-06T17:00:53Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2052397</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2052397" />
    <title>Comment from Satyam on 2009-02-06</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Patrick,</p>

<p>No, there is no immediate way to do what you want.  Normally, each individual update/addition/deletion is transmitted to the server and it is not often that you would let the user do a bunch of modifications and send to the server all the lot at once, even those records that have not been modified. </p>

<p>The DataSource is only that, a generic utility to read data sources, but once it has fetched, extracted and parsed the values, it passes them on to the component that will consume them, in this case, the DataTable, without holding any reference to them.  So, the place to look for them is in the DataTable.</p>

<p>Within the DataTable, method getRecordSet will point you to the DataTable's own storage.  You can loop through it.  Within RecordSet, method getLength provides you the actual number of records, and method getRecord returns each Record and method getData of the Record object, without arguments, gives you all the values at once or you can fetch the values you want by asking explicitly for each.</p>]]>
    </content>
    <published>2009-02-06T18:55:26Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2055373</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2055373" />
    <title>Comment from Stefan on 2009-03-17</title>
    <author>
        <name>Stefan</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>You can hide and show rows in a yui dataTable by manipulating e.g. the tr style.</p>

<p>Example:</p>

<p>function unHideTableRow(searchData) {</p>

<p>	if (myDataTable != null) {<br />
		var recordSet = myDataTable.getRecordSet();<br />
		for (var i = 0; i 
					<br />
			record = recordSet.getRecord(i);<br />
			if (searchData == record.getData('searchData')) {<br />
				var trEl = myDataTable.getTrEl(i);<br />
				trEl.style.display = ''; //set 'none' to hide...<br />
		    	break;<br />
			}<br />
		}<br />
	}<br />
}<br />
</p>]]>
    </content>
    <published>2009-03-17T21:29:13Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2058212</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2058212" />
    <title>Comment from SlugO on 2009-04-23</title>
    <author>
        <name>SlugO</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Is there a way to add attributes to DataTable's checkboxes?  I'm asking cos I need to be able to assign them unique name="" attributes so that my PHP code can go through them.</p>

<p>It works fine in the HTML table that the DataTable parses but I can't really grasp how to handle DataTable's checkboxes, they just get generated.</p>]]>
    </content>
    <published>2009-04-23T19:33:38Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2058213</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2058213" />
    <title>Comment from SlugO on 2009-04-23</title>
    <author>
        <name>SlugO</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Is there a way to add attributes to DataTable's checkboxes?  I'm asking cos I need to be able to assign them unique name="" attributes so that my PHP code can go through them.</p>

<p>It works fine in the HTML table that the DataTable parses but I can't really grasp how to handle DataTable's checkboxes, they just get generated.</p>]]>
    </content>
    <published>2009-04-23T19:34:36Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2058215</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2058215" />
    <title>Comment from SlugO on 2009-04-23</title>
    <author>
        <name>SlugO</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Is there a way to add attributes to DataTable's checkboxes?  I'm asking cos I need to be able to assign them unique name="" attributes so that my PHP code can go through them.</p>

<p>It works fine in the HTML table that the DataTable parses but I can't really grasp how to handle DataTable's checkboxes, they just get generated.</p>]]>
    </content>
    <published>2009-04-23T19:35:58Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2058255</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2058255" />
    <title>Comment from Satyam on 2009-04-24</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Checkboxes don't have names because they are not meant to be directly submitted to a server but processed within the page, with JavaScript and the DOM and then, if needed, assembled into an AJAX request.  </p>

<p>If you want to put names on them, you should define your own custom formatter function for the column holding the checkboxes and draw the checkboxes yourself with whatever attributes you want</p>]]>
    </content>
    <published>2009-04-24T08:35:06Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2058607</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2058607" />
    <title>Comment from Michael on 2009-04-29</title>
    <author>
        <name>Michael</name>
        <uri>http://thehumblecoder.wordpress.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://thehumblecoder.wordpress.com">
        <![CDATA[<p>I'm trying to integrate the JQuery Sparkline inside one of the rows. I created a customer formater that adds a class to a span element. Normally I call a JQuery method as follows:</p>

<p> $('.inlinesparkline').sparkline();</p>

<p>to render the sparkline. But the HTML isn't actually there yet. Is there any support for calling additional javascript like this after the AJAX request and the new html is rendered?</p>

<p>Thanks</p>]]>
    </content>
    <published>2009-04-29T23:56:50Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2058623</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2058623" />
    <title>Comment from Satyam on 2009-04-30</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Michael,</p>

<p>The DataTable will fire the initEvent when it is done with the initial rendering and renderEvent every time it has to redraw itself due to sorting, paging or whatever that makes it redraw the full table.  With either of them you will be certain the full page is drawn.</p>]]>
    </content>
    <published>2009-04-30T07:04:35Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2070067</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2070067" />
    <title>Comment from Raaj on 2009-08-10</title>
    <author>
        <name>Raaj</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I am trying to use jsp page for calling the datasource into the yui data table. But , the datas are not inserted into the data table.</p>

<p>I get " tbodies.length is null or not an object" and at the same time the data table is in the loading state.</p>

<p><br />
Could anyone help me out</p>]]>
    </content>
    <published>2009-08-10T08:27:04Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2070074</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2070074" />
    <title>Comment from Satyam on 2009-08-10</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Raaj,</p>

<p>The YUI forums, at:</p>

<p><a href="http://yuilibrary.com/forum/">http://yuilibrary.com/forum/</a></p>

<p>will be a better place to get support.  It has a section for DataTable/DataSource.</p>

<p>Satyam</p>]]>
    </content>
    <published>2009-08-10T12:43:53Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2092426</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2092426" />
    <title>Comment from charlie on 2009-09-10</title>
    <author>
        <name>charlie</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi,</p>

<p>An interesting introduction. I am a bit of a newbie so would it be possible for you to set out how to load the data from an XML file that looks like this? (It was generated by serialisation in vb .net)</p>

<p>Thanks</p>

<p>Charles</p>

<p>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;CalculationResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;<br />
  &lt;TotalLiability&gt;0&lt;/TotalLiability&gt;<br />
  &lt;CashFlowList&gt;<br />
    &lt;CashFlow&gt;<br />
      &lt;Year&gt;0&lt;/Year&gt;<br />
      &lt;Age&gt;60&lt;/Age&gt;<br />
      &lt;AmountBeforeDiscount&gt;700&lt;/AmountBeforeDiscount&gt;<br />
      &lt;DiscountFactorCurrent&gt;0.97590007294853309&lt;/DiscountFactorCurrent&gt;<br />
      &lt;DiscountFactor&gt;0.95238095238095233&lt;/DiscountFactor&gt;<br />
      &lt;DecrementRateCurrent&gt;0&lt;/DecrementRateCurrent&gt;<br />
      &lt;DecrementFactor&gt;0&lt;/DecrementFactor&gt;<br />
      &lt;AmountDiscounted&gt;0&lt;/AmountDiscounted&gt;<br />
      &lt;Years&gt;0&lt;/Years&gt;<br />
    &lt;/CashFlow&gt;<br />
    &lt;CashFlow&gt;<br />
      &lt;Year&gt;1&lt;/Year&gt;<br />
      &lt;Age&gt;60&lt;/Age&gt;<br />
      &lt;AmountBeforeDiscount&gt;300&lt;/AmountBeforeDiscount&gt;<br />
      &lt;DiscountFactorCurrent&gt;0.97590007294853309&lt;/DiscountFactorCurrent&gt;<br />
      &lt;DiscountFactor&gt;0.95238095238095233&lt;/DiscountFactor&gt;<br />
      &lt;DecrementRateCurrent&gt;0&lt;/DecrementRateCurrent&gt;<br />
      &lt;DecrementFactor&gt;0&lt;/DecrementFactor&gt;<br />
      &lt;AmountDiscounted&gt;0&lt;/AmountDiscounted&gt;<br />
      &lt;Years&gt;0&lt;/Years&gt;<br />
    &lt;/CashFlow&gt;<br />
    &lt;CashFlow&gt;<br />
      &lt;Year&gt;1&lt;/Year&gt;<br />
      &lt;Age&gt;61&lt;/Age&gt;<br />
      &lt;AmountBeforeDiscount&gt;800&lt;/AmountBeforeDiscount&gt;<br />
      &lt;DiscountFactorCurrent&gt;0.97590007294853309&lt;/DiscountFactorCurrent&gt;<br />
      &lt;DiscountFactor&gt;0.95238095238095233&lt;/DiscountFactor&gt;<br />
      &lt;DecrementRateCurrent&gt;0&lt;/DecrementRateCurrent&gt;<br />
      &lt;DecrementFactor&gt;0&lt;/DecrementFactor&gt;<br />
      &lt;AmountDiscounted&gt;0&lt;/AmountDiscounted&gt;<br />
      &lt;Years&gt;0&lt;/Years&gt;<br />
    &lt;/CashFlow&gt;<br />
</p>]]>
    </content>
    <published>2009-09-10T22:03:14Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2092974</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2092974" />
    <title>Comment from Satyam on 2009-09-11</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>As the comment just above yours says, there is a support forum where your question can be properly answered.</p>]]>
    </content>
    <published>2009-09-11T08:09:53Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2123588</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2123588" />
    <title>Comment from Venkatesh on 2009-10-01</title>
    <author>
        <name>Venkatesh</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>HI ,</p>

<p>I have a scenario where i need to bind the values in the yui datable ceel to a form.<br />
Please let me know how to handle this part.</p>

<p>Also please let me know how to update the HTML table with the value of my yu datatable.</p>]]>
    </content>
    <published>2009-10-01T09:05:01Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.23517-comment:2123668</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.23517" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/06/yui-datatable-component-1.html#comment-2123668" />
    <title>Comment from Satyam on 2009-10-01</title>
    <author>
        <name>Satyam</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Please use the forum for support issues:</p>

<p><a href="http://yuilibrary.com/forum/">http://yuilibrary.com/forum/</a></p>

<p>Satyam</p>]]>
    </content>
    <published>2009-10-01T10:09:38Z</published>
  </entry>

</feed
