Chytkam said: One issue I have been having is I would like to only have one row "open" at a time
$('#example td.control').live( 'click', function () {
var nTr = this.parentNode;
var i = $.inArray( nTr, anOpen );
$(anOpen).each( function () {
if ( this !== nTr ) {
$('td.control', this).click();
}
} );
if ( i === -1 ) {
$('img', this).attr( 'src', sImageUrl+"details_close.png" );
var nDetailsRow = oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push( nTr );
}
else {
$('img', this).attr( 'src', sImageUrl+"details_open.png" );
$('div.innerDetails', $(nTr).next()[0]).slideUp( function () {
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
} );
}
} );
} );
$('#item_table td.control').live( 'click', function () {
var nTr = this.parentNode;
var i = $.inArray( nTr, anOpen );
$(anOpen).each( function () {
if ( this !== nTr ) {
$('td.control', this).click();
}
} );
if ( i === -1 ) {
$('img', this).attr( 'src', sImageUrl+"details_close.png" );
$('div.innerDetails', nDetailsRow).slideDown();
var nDetailsRow = oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
anOpen.push( nTr );
$(nTr).addClass('row_selected');
clickedRowId = $(nTr).attr('id');
$('#btnEditRow').button( "option", "disabled", false );
} else {
$('img', this).attr( 'src', sImageUrl+"details_open.png" );
$('div.innerDetails', $(nTr).next()[0]).slideUp( function () {
$(nTr).removeClass('row_selected');
clickedRowId = 0;
oTable.fnClose( nTr );
anOpen.splice( i, 1 );
$('#btnEditRow').button( "option", "disabled", true );
} );
}
return false;
} ); var aData = oTable.fnGetData( nTr ); var id = aData[1];
var id = $(nTr.children[1]).html();
fnOnAdded: function(status)
{
oTable.fnDraw(false);
$(anOpen).each( function () {
if ( this == nTr ) {
$('td.control', this).click();
}
});
return true;
}
but no luck.
<table>
<thead></thead>
<tbody>
<tr>
<td>"parent" table</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>nested table</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
// the table containing the index data
var oTable_2 = "";
// the select row
var nTargetRow = "";
//
//
var aData = ""; // holds the text for selected row (column position is critical)
/* -----------------------------------------------------------------------
Jquery Ajax action scrpts
----------------------------------------------------------------------- */
// Method retrieves the selected row index id and executes the ajax call
function getModDetails()
{
//alert('getModDetails');
// retrieve the data from the selected row
aData = oTable_2.fnGetData( nTargetRow );
// build the url for the ajax call to use
var cfcUrl = '#application.ajax_url#';
cfcUrl +='RemoteModDetails.cfc?';
cfcUrl += 'method=getPos';
cfcUrl +='&porderid=' + aData[1] ;
// make the ajax call
$.ajax(
{
type: "GET",
url: cfcUrl,
cache: false,
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: function (objResponse )
{ ;
if(objResponse.SUCCESS)
{
openModDetailRow(objResponse.DATA);
}
else
{
ShowErrors(objResponse.ERRORS);
}
},
error : function(jqXHR, textStatus, errorThrown ) {
ajaxErrorHandler( jqXHR, textStatus, errorThrown );
}
});
}
// Function ajaxErrorHandler
// DESCRITPION: Error Handler fir the error message for failed ajax call'
// PARAMETERS:
// jqXHR = The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object,
// textStatus = a string describing the type of error that occurred
// and an optional exception object, if one occurred.
// Possible values for the second argument (besides null) are
// "timeout", "error", "abort", and "parsererror".
// errorThrown = the textual portion of the HTTP status, such as "Not Found"
// or "Internal Server Error."
function ajaxErrorHandler( jqXHR, textStatus, errorThrown)
{
alert('Unable to retieve the requested information due to a server error');
}
// Handle the failed response error
function ShowErrors( statusMsg)
{
alert('Unable to retieve the requested information. Status: ' + statusMsg);
}
// create the indormation row based on the data retruned by the ajax call
function openModDetailRow(indexInfo)
{
/* Assumes only one row returns; additional rows ignored */
var aReqNumID = indexInfo.DATA [0][0];
var aPorderID = indexInfo.DATA [0][1];
var aRequistionNum = indexInfo.DATA [0][2];
var aAwardDte = indexInfo.DATA [0][3];
var aAwardAmount = indexInfo.DATA [0][4];
var aDteEntered = indexInfo.DATA [0][5];
var aEnteredBy = indexInfo.DATA [0][6];
var aDteMod = indexInfo.DATA [0][7];
var aModBy = indexInfo.DATA [0][8];
var aValidFlag = indexInfo.DATA [0][9];
var aModNum = indexInfo.DATA [0][10];
var aDescription = indexInfo.DATA [0][11];
;
// create the additonal information table
var sOut = '<table align="left" width="95%" cellpadding="2" cellspacing="0" border="1" class="hiddenTbl ui-widget-content">';
// row 1
sOut += '<tr><td><strong>Mod Number:</strong><br> <strong style="color:##FF0;"> '+ aModNum +'</strong></td>';
sOut += '<td><strong>Requsition Numbeer:</strong><br> '+aRequistionNum + '</td><td><strong> Award Amount:</strong><br> <strong style="color:##FF0;">$' + aAwardAmount.toFixed(2) + '</strong></td></tr>';
// row 2
sOut += '<tr><td ><strong>Award Date:</strong><br>'+ aAwardDte + ' </td><td ><strong>Description:</strong><br> ' + aDescription + '</td><td> </td></tr>';
// end of table
sOut += '</table>';
// display the row
oTable_2.fnOpen( nTargetRow, sOut, 'details' );
}
/* -----------------------------------------------------------------------
* Jquery Display script
* ----------------------------------------------------------------------- */
$(document).ready(function()
{
/*
* Insert a 'details' column to the table
*/
var nCloneTh = document.createElement( 'th' ); // for header
var nCloneThF = document.createElement( 'th' ); // for footer
var nCloneTd = document.createElement( 'td' ); // for body
nCloneTd.innerHTML = '<img src="./images/details_open.png">';
nCloneTd.className = "center";
// add blank header
$('##MVW thead tr').each( function () {
this.insertBefore( nCloneTh, this.childNodes[0] );
} );
// add blank footer header
$('##MVW tfoot tr').each( function () {
this.insertBefore( nCloneThF, this.childNodes[0] );
} );
// add icon open/close info rowrow
$('##MVW tbody tr').each( function () {
this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] );
} );
// run the jquery data table script
oTable_2 = $('##MVW');
oTable_2.dataTable({
"aoColumnDefs":
[ { "bSortable": false, "aTargets": [ 0 ] } ],
"aaSorting": [[1, 'asc']],
"iDisplayLength": 5,
"aLengthMenu": [[5,10, 25, 50, 100, -1], [5,10, 25, 50, 100, "All"]],
"bJQueryUI": true
});/* end data table */
/* 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
*/
$('##MVW tbody td img').live('click', function () {
nTargetRow = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "./images/details_open.png";
oTable_2.fnClose( nTargetRow );
}
else
{
this.src = "./images/details_close.png";
getModDetails();
}
} );
});
/* end ready */
</script>
Is that possible to expand the rows in inner table ?
$("#expandAllTR").click(function (){
$("#parentTable tbody tr").each(function() {
if (oTable.fnIsOpen(this)){
oTable.fnClose(this);
}else{
var position = oTable.fnGetPosition(this);
var info = oTable.fnGetData(position)[11];
oTable.fnOpen( this, info, "info_row" );
}
});
if($("#expandAllTR").html()=="Expand All"){
$("#expandAllTR").html("Collapse All");
}else{
$("#expandAllTR").html("Expand All");
}
});
$("#parentTable tbody tr").each(function() {
oTable.$('tr').each(function() {
fnFooterCallback: function( nFoot, aData, iStart, iEnd, aiDisplay ) {
$(oTable).find("tr").each(function() {
if (oTable.fnIsOpen(this)) {
oTable.fnClose(this);
}
});
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewData("Title")</title>
<link href="@Url.Content("~/Content/DataTables-1.9.4/media/css/jquery.dataTables.css")" rel="stylesheet" type="text/css" />
<!--<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />-->
<link href="@Url.Content("~/Content/DataTables-1.9.4/media/css/demo_table.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-2.6.2.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js")" type="text/javascript"></script>
</head>
<body>
@RenderBody()
</body>
</html>
@ModelType MVC3Test.BatchCollection
@Code
ViewData("Title") = "Batchlist2"
End Code
<h2>Batchlist2</h2>
<table id="batch_table" class="display">
<thead>
<tr>
<th></th>
<th>BatchID</th>
<th>Transmitted Date/Time</th>
<th>Completed Date/Time</th>
<th>Created By</th>
<th>Created Date/Time</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript" language="javascript">
// This will run the code instead the function() {} as soon as the page is ready.
// Hence: Document.ready
$(document).ready(function () {
var anOpen = [];
var oTable;
var sImageURL = "/Images/"; //path to image files
// AJAX call to get batch list
// it will return into the data object
$.ajax(
{
type: "GET",
url: '@Url.Action("FetchBatchList", "Batch")',
error: function (xhr, statusText, errorThrown) {
if (statusText === 'timeout')
alert('The server is not responding');
if (statusText === 'error')
alert("Error: " + errorThrown);
}, //end of ajax error block
success: function (data) {
//"sAjaxSource": "",
// Create Data Table
oTable = $('#batch_table').dataTable(
{
"bProcessing": true,
"aaData": data.BatchList, // Initialize datatables with data object
"aoColumns": [ // Bind table columns with properties
{
"mData": null,
"sClass": "control center",
"sDefaultContent": '<img src="' + sImageURL + 'details_open.png' + '">'
},
{ "mData": "BatchID" },
{ "mData": "Transmitted_DateTime" },
{ "mData": "Completed_DateTime" },
{ "mData": "Created_EmpID" },
{ "mData": "Created_DTTM" }
]
}); // End dataTable()
//debugger;
} //end of ajax success block
}); // end $.ajax call
}); // end $(document).ready(....
// animation control code
$('#batch_table td.control').on('click', function () { //.live is deprecated in jQuery 1.7... use .on instead
alert('Hello from animation control code');
var nTr = this.parentNode;
var i = $.inArray(nTr, anOpen);
debugger;
if (i === -1) {
$('img', this).attr('src', sImageURL + "details_close.png");
var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
$('div.innerDetails', nDetailsRow).slidedown();
anOpen.push(nTr);
}
else {
$('img', this).attr('src', sImageURL + "details_open.png");
$('div.innerDetails', $(nTr).next()[0]).slideup(function () {
oTable.fnClose(nTr);
anOpen.splice(i, 1);
});
}
});
// detail table row html goes in the following section
function fnFormatDetails(oTable, nTr) {
var oData = oTable.fnGetData(nTr);
debugger;
var tranData; //this will contain an instance of a transaction object from the transactions collection
for (tranData in oData.TranCollection) {
var sOut = '<div class="innerDetails">' +
'<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
'<tr>' +
'<td>TransactionID:</td><td>' + tranData.ID + '</td>' +
'<td>SOR_ID:</td><td>' + tranData.SystemOfRecordID + '</td>' +
'<td>PostingFlag:</td><td>' + tranData.PostingFlag + '</td>' +
'<td>Posting_DTTM:</td><td>' + tranData.Posting_DTTM + '</td>' +
'<td>PostingMessage:</td><td>' + tranData.PostingMessage + '</td>' +
'<td>PostingMessage:</td><td>' + tranData.XMLTransactionData + '</td>' +
'</tr>' +
'</table>' +
'</div>';
return sOut;
}
}
</script>
$('#basetable td.control').live( 'click', function () {
var nTr = this.parentNode;
var i = $.inArray( nTr, anOpen );
if ( i === -1 ) {
$('img', this).attr( 'src', "/mf/forward/images/details_close.png" );
baseTable.fnOpen( nTr, fnFormatDetails(baseTable, nTr), 'details' );
anOpen.push( nTr );
}
else {
$('img', this).attr( 'src', "/mf/forward/images/details_open.png" );
baseTable.fnClose( nTr );
anOpen.splice( i, 1 );
}
} );
function fnFormatDetails( oTable, nTr )
{
//alert(nTr);
var oData = oTable.fnGetData( nTr );
//alert(oData[11]);
var fundNum = oData[11].trim();
var sOut =
'<div class="innerDetails">'+
'<script type="text/javascript">' +
'$("#tableDetails'+fundNum.trim()+'").dataTable( {'+
'"bFilter": false,'+
'"bPaginate": false,'+
'"bInfo": false,'+
'"bAutoWidth": false,'+
'"oLanguage": {'+
' "sEmptyTable": "No transactions were found. Please modify your criteria and search again."'+
'},'+
'"aoColumns": ['+
' { "sTitle": "Trade Date",'+
' "sClass": "left" },'+
' { "sTitle": "Description",'+
' "sClass": "right" },'+
' { "sTitle": "Price",'+
' "sClass": "right" },'+
' { "sTitle": "Shares",'+
' "sClass": "right" },'+
' { "sTitle": "Amount",'+
' "sClass": "right" }'+
']'+
'});' +
'</' +
'script>' +
'<table id="tableDetails'+fundNum.trim()+'" class="display" cellpadding="0" cellspacing="0" border="0">'+
'<tbody>';
if(detailsTableData.length > 0 )
{
for(var i=0;i<detailsTableData.length;i++)
{
if(detailsTableData[i][0] === fundNum )
{
sOut +='<tr>'+
'<td>'+detailsTableData[i][1]+'</td>'+
'<td>'+detailsTableData[i][2]+'</td>'+
'<td>'+detailsTableData[i][3]+'</td>'+
'<td>'+detailsTableData[i][4]+'</td>'+
'<td>'+detailsTableData[i][5]+'</td>'+
'</tr>';
}
}
sOut += '</tbody><tfoot>' +
'<tr>' +
'<th></th>' +
'<th></th>' +
'<th></th>' +
'<th></th>' +
'<th></th>' +
'</tr>' +
'</tfoot>';
sOut += '</table>'+
'</div>';
}
return sOut;
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.