Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate id for row in JSF datatable
    primarykey
    data
    text
    <p>I am trying to achieve the expand/contract functionality of table rows in JSF using core faces implementation. As answered in one of my earlier thread this is not straight forward to achieve in core faces implementation. So, I thought of using HTML + jQuery to achieve the functionality. I am calling the row with +/- gif as parent row and the rows that are to be expanded and contracted are its child rows. To make parent row aware of which child it needs to show or hide, I am making use of jquery and assigning row id to each <code>&lt;tr&gt;</code>. If the parent <code>row-id="row1234"</code>, then the child row will have <code>row-id="row1234-child"</code>. </p> <p>Below is the Jquery Script and HTML code:</p> <pre><code> &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;script src="jquery.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $('.expand').click(function() { if( $(this).hasClass('.hidden') ) { $(this).attr("src", "plus.gif"); } else { $(this).attr("src", "subtract1.gif"); } $(this).toggleClass('hidden'); $(this).parent().parent().siblings('#'+$(this).parent().parent().attr('id')+'-child').toggle(); }); }); &lt;/script&gt; &lt;style&gt; .hover {background-color:#00f; color: #fff;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;table border="1" cellspacing="0" cellpadding="0"&gt; &lt;thead&gt; &lt;tr&gt;&lt;th&gt;Rolling &lt;/th&gt;&lt;th&gt;transaction&lt;/th&gt;&lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;TR class="parent" id="row123" style="cursor: pointer; " title="Click to expand/collapse"&gt; &lt;TD&gt;123&lt;/TD&gt; &lt;TD colspan="2"&gt;&lt;img class="expand" src="plus.gif"/&gt;ABC&lt;/TD&gt; &lt;TD&gt;100&lt;/TD&gt; &lt;/TR&gt; &lt;TR ID="row123-child" style="display: none; "&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;TD&gt;2007-01-02&lt;/TD&gt; &lt;TD&gt;A short description&lt;/TD&gt; &lt;TD&gt;15&lt;/TD&gt; &lt;/TR&gt; &lt;TR ID="row123-child" style="display: none; "&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;TD&gt;2007-02-03&lt;/TD&gt; &lt;TD&gt;Another description&lt;/TD&gt; &lt;TD&gt;45&lt;/TD&gt; &lt;/TR&gt; &lt;TR ID="row123-child" style="display: none; "&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;TD&gt;2007-03-04&lt;/TD&gt; &lt;TD&gt;More Stuff&lt;/TD&gt; &lt;TD&gt;40&lt;/TD&gt; &lt;/TR&gt; &lt;TR class="parent" id="row2345" style="cursor: pointer; " title="Click to expand/collapse"&gt; &lt;TD&gt;234&lt;/TD&gt; &lt;TD colspan="2"&gt;&lt;img class="expand" src="plus.gif"/&gt;DEF&lt;/TD&gt; &lt;TD&gt;100&lt;/TD&gt; &lt;/TR&gt; &lt;TR ID="row2345-child" style="display: none; "&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;TD&gt;2007-01-02&lt;/TD&gt; &lt;TD&gt;A short description&lt;/TD&gt; &lt;TD&gt;15&lt;/TD&gt; &lt;/TR&gt; &lt;TR ID="row2345-child" style="display: none; "&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;TD&gt;2007-02-03&lt;/TD&gt; &lt;TD&gt;Another description&lt;/TD&gt; &lt;TD&gt;45&lt;/TD&gt; &lt;/TR&gt; &lt;TR ID="row2345-child" style="display: none; "&gt; &lt;TD&gt;&amp;nbsp;&lt;/TD&gt; &lt;TD&gt;2007-03-04&lt;/TD&gt; &lt;TD&gt;More Stuff&lt;/TD&gt; &lt;TD&gt;40&lt;/TD&gt; &lt;/TR&gt; &lt;TR class="parent" id="row3456" style="cursor: pointer; " title="Click to expand/collapse"&gt; &lt;TD&gt;345&lt;/TD&gt; &lt;TD colspan="2"&gt;HIJ&lt;/TD&gt; &lt;TD&gt;100&lt;/TD&gt; &lt;/TR&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/body &lt;/html&gt; </code></pre> <p>So, I was wondering whether I can generate row id for datatable or if there is a better solution for it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload