-
1. Re: rich:dataTable - row selection/highlighting
icai Apr 30, 2007 5:32 PM (in response to hfu1)I don't know if it can be useful to you. But if it helps it'll be my pleasure.
onRowClick i call a jsFunction and pass it rowindex as a parameter. I set this rowIndex in one hidden variable (in bean). Now oncomplete event of jsFunction I call a javascript function. This function iterates the datatable and when it finds the rowIndex saved in hidden variable it higlights that row. This iteration also helps me to change the color of rows on onMouseOver and onMouseOut event but at the same time do not reset the color of highlighted row.
Hope this helps. -
2. Re: rich:dataTable - row selection/highlighting
vh May 16, 2007 9:29 PM (in response to hfu1)I am actually looking for the answer for a different question:
I want to be able to click on a row to select this row and do some operation on this row (like delete). The problem is: how do I know a row is clicked on in my bean code.
By looking at your posting, I kind of getting an idea. Can you explain that in more detail? sample code will be very helpful. -
3. Re: rich:dataTable - row selection/highlighting
vh May 16, 2007 11:49 PM (in response to hfu1)I think data="#{row.id}" is the way to pass the row id to the Bean's action method, but how can the action method get this id?
how to "iterates the datatable" with js? Do you mean parse the generated html? -
4. Re: rich:dataTable - row selection/highlighting
ilya_shaikovsky May 17, 2007 6:18 AM (in response to hfu1)data - used to transfer some object from server to client.
Use parameters inside your command contols to transwer rowKey to server. -
5. Re: rich:dataTable - row selection/highlighting
jmiguel77 May 21, 2007 12:32 PM (in response to hfu1)I have some code that works for me in highlighting one single row and cleaning any other highlighted (if any)
what i am really looking for is how to call a backingBean method by making an a4j.ajax.submit when the row is clicked (and also highlighted) so i can work with the current selected row in the backing bean code
thanks -
6. Re: rich:dataTable - row selection/highlighting
ilya_shaikovsky May 22, 2007 7:50 AM (in response to hfu1)a4j:support on the onclick event placed in column should be the right way.
-
7. Re: rich:dataTable - row selection/highlighting
vh May 22, 2007 10:58 PM (in response to hfu1)But how to get the selected row id and how to pass it to the backing bean?
I found a way that onRowClick(), I parse the html of "this", and pick up the id (which is saved in a hidden column), then I put the row id into a hidden text field, submit the form to send the hiddend text field content to the server, so the bean can get it.
Is there a better solution? I suggest RichFaces team put in a build in support for this. ICEFaces has this feature. -
8. Re: rich:dataTable - row selection/highlighting
ilya_shaikovsky May 23, 2007 6:24 AM (in response to hfu1)use rowKey which you may pass to server through f:param.
-
9. Re: rich:dataTable - row selection/highlighting
hfu1 May 29, 2007 6:09 AM (in response to hfu1)Ok thanks everyone for their replies, using a combination of techniques I did the following:
1) Added a hidden column in my data table - ID. This is my internal Id which does not need to be seen by a user.
2) used Javascript on the page to do the row highlighting using the <a4j:support> events - onRowClick, onSubmit and onComplete. I had to write some functions that remembers which row (id) has been selected. The functions will ensure that the old rows have been deselected.
3) used the rowClasses attribute on the data table to set initially selected rows (if any). -
10. Re: rich:dataTable - row selection/highlighting
perfectpitch May 30, 2007 9:31 AM (in response to hfu1)Dear Hfu1, I'd really appreciate some code snippets of your solution. I'm trying to create a 'details' table to be shown when users click rows of another table, and I believe your strategy fits well.
Thanks in advance. -
11. Re: rich:dataTable - row selection/highlighting
hfu1 May 31, 2007 5:24 AM (in response to hfu1)PerfectPitch, first make sure you add a hidden column with the IDs.
Then you need some javascript to handle the row colouring, both selected/unselected rows and also a colour to handle hovering You need something like this, note the css class names come from a stylesheet that you will define that should contain the colours for the rows.var styleHolder; var clickedRow; var lastSelectedId = 'none'; var tableId; var selectedRowClassName = 'selectedRow'; var hoveredRowClassName = 'hoveredRow'; var unSelectedRowClassName = 'unSelectedRow'; function onBeforePage(tableName) { if (lastSelectedId == 'none') { var rows = findTable(tableName).rows; if (rows.length > 1) { lastSelectedId = rows[1].cells[0].innerHTML; } } } function onPage(tableName) { onTableRefresh(tableName); } function findTable(tableName) { var allTables = document.getElementsByTagName("table"); var table = null; for (i=1; i<allTables.length; i++) { if (allTables.id.indexOf(tableName) > -1) { table = allTables; } } return table; } function onOver(elmt) { tableId = elmt.parentNode.parentNode.id; if(elmt.className.indexOf(selectedRowClassName)==-1) { styleHolder = elmt.className; elmt.className = hoveredRowClassName; } } function onOut(elmt) { if(elmt.className.indexOf(selectedRowClassName)==-1) { elmt.className = styleHolder; } } function onTableRefresh(tableName) { var allRows = findTable(tableName).rows; for (i=1; i<allRows.length; i++) { var rowId = allRows.cells[0].innerHTML; if (rowId != lastSelectedId) { allRows.className = unSelectedRowClassName; } else { allRows.className = selectedRowClassName; } } } function onClick(elmt) { var selectedId = elmt.cells[0].innerHTML; lastSelectedId = selectedId; var allRows = elmt.parentNode.parentNode.rows; for (i=1; i<allRows.length; i++) { var rowId = allRows.cells[0].innerHTML; if (rowId != selectedId) { allRows.className = unSelectedRowClassName } else { allRows.className = selectedRowClassName } } }
Your datatable tag should have these attributes:
onRowMouseOver="onOver(this)"
onRowMouseOut="onOut(this)"
The table should enclose an a4j:support tag which handles a row click - this will allow you to update your 'details' panel.
<a4j:support id="rowSelectedLink" event="onRowClick" data="#{myRow.id}" actionListener="#{myTable.rowSelected}" onsubmit="onClick(this)" reRender="detailsPanel"/>
Hope this helps,
H -
12. Re: rich:dataTable - row selection/highlighting
perfectpitch Jun 1, 2007 5:23 AM (in response to hfu1)I'll have a look at it ASAP. Thanks for your kind support.