Using DataTables with Struts
Using DataTables with Struts
I am using Struts 1 as the front-end framework and on one of the page I am using DataTable to display result.
So now I am having problem doing AJAX call to Struts action to retrieve those record. Can anyone walk me through how I can do such call.
Also as next step I am implementing "hidden row detail" but on my own way. What I am doing is once table is loaded with top level data (e.g. directory name) if user click on any of those then it should display file list under it which in addition will have link to download that file. And that file is download through one of the Struts action.
It will be great help if any one can suggest me the best way to do it.
Thanks in advance.
So now I am having problem doing AJAX call to Struts action to retrieve those record. Can anyone walk me through how I can do such call.
Also as next step I am implementing "hidden row detail" but on my own way. What I am doing is once table is loaded with top level data (e.g. directory name) if user click on any of those then it should display file list under it which in addition will have link to download that file. And that file is download through one of the Struts action.
It will be great help if any one can suggest me the best way to do it.
Thanks in advance.
This discussion has been closed.
Replies
Allan
[code]
/* Formating function for row details */
function fnFormatDetails ( oTable, nTr )
{
var aData = oTable.fnGetData( nTr );
var sOut = '';
sOut += //This must be links of sub list for this particular record.
sOut += '';
return sOut;
}
$(document).ready(function() {
/*
* Insert a 'details' column to the table
*/
var nCloneTh = document.createElement( 'th' );
var nCloneTd = document.createElement( 'td' );
nCloneTd.innerHTML = '';
nCloneTd.className = "center";
$('#documents thead tr').each( function () {
this.insertBefore( nCloneTh, this.childNodes[0] );
} );
$('#documents tbody tr').each( function () {
this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] );
} );
/*
* Initialse DataTables
*/
var oTable = $('#documents').dataTable({
"aoColumns": [
{ "bSortable": false },
{ "bVisible": false },
null,
{ "sClass": "center" },
{ "sType": "file-size" },
{ "sClass": "center" },
{ "sClass": "center" }
],
"aaSorting": [[1, 'asc']]
});
alert( oTable.fnVersionCheck( '1.6.0' ) );
/* Add event listener for opening and closing details
* Note that the indicator for showing which row is open is not
* controlled by DataTables, rather it is done here
*/
$('td img', oTable.fnGetNodes() ).each( function () {
$(this).click( function () {
var nTr = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "images/details_open.png";
oTable.fnClose( nTr );
}
else
{
/* Open this row */
this.src = "images/details_close.png";
//Do I have to call server here to get sublist for this record?
oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
}
} );
} );
});
//My Table headings
<%
//JSP code to get list from the server.
%>
// Display the list.
[/code]