1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-02-18 16:54:14 +01:00

Fix: fnOpen - when passed a TR element (or indeed any other element) that is not part of the master table (i.e. under control of DataTables), DatTables would try to "open" the row anyway - which was wrong. So now check that the node given is a TR element under control of DataTables, otherwise silently return. This is useful for using fnOpen when bound to all TR elements in the TBODY with a live event handler (i.e the click would also occur on the opened row).

This commit is contained in:
Allan Jardine 2012-01-15 10:09:06 +00:00
parent e1146e2f9d
commit 0c3dadbed9
2 changed files with 23 additions and 5 deletions

View File

@ -4482,7 +4482,7 @@
iColumn, iColumns, oData, sNodeName, iStart=0, iEnd=iRows;
/* Allow the collection to be limited to just one row */
if ( iIndividualRow )
if ( iIndividualRow !== undefined )
{
iStart = iIndividualRow;
iEnd = iIndividualRow+1;
@ -5503,7 +5503,9 @@
* @param {node} nTr The table row to 'open'
* @param {string|node|jQuery} mHtml The HTML to put into the row
* @param {string} sClass Class to give the new TD cell
* @returns {node} The row opened
* @returns {node} The row opened. Note that if the table row passed in as the
* first parameter, is not found in the table, this method will silently
* return.
*
* @example
* $(document).ready(function() {
@ -5525,6 +5527,13 @@
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
/* Check that the row given is in the table */
var nTableRows = _fnGetTrNodes( oSettings );
if ( $.inArray(nTr, nTableRows) === -1 )
{
return;
}
/* the old open one if there is one */
this.fnClose( nTr );
@ -5546,7 +5555,7 @@
/* If the nTr isn't on the page at the moment - then we don't insert at the moment */
var nTrs = $('tr', oSettings.nTBody);
if ( $.inArray(nTr, nTrs) != -1 )
if ( $.inArray(nTr, nTrs) != -1 )
{
$(nNewRow).insertAfter(nTr);
}

View File

@ -762,7 +762,9 @@ this.fnIsOpen = function( nTr )
* @param {node} nTr The table row to 'open'
* @param {string|node|jQuery} mHtml The HTML to put into the row
* @param {string} sClass Class to give the new TD cell
* @returns {node} The row opened
* @returns {node} The row opened. Note that if the table row passed in as the
* first parameter, is not found in the table, this method will silently
* return.
*
* @example
* $(document).ready(function() {
@ -784,6 +786,13 @@ this.fnOpen = function( nTr, mHtml, sClass )
{
/* Find settings from table node */
var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
/* Check that the row given is in the table */
var nTableRows = _fnGetTrNodes( oSettings );
if ( $.inArray(nTr, nTableRows) === -1 )
{
return;
}
/* the old open one if there is one */
this.fnClose( nTr );
@ -805,7 +814,7 @@ this.fnOpen = function( nTr, mHtml, sClass )
/* If the nTr isn't on the page at the moment - then we don't insert at the moment */
var nTrs = $('tr', oSettings.nTBody);
if ( $.inArray(nTr, nTrs) != -1 )
if ( $.inArray(nTr, nTrs) != -1 )
{
$(nNewRow).insertAfter(nTr);
}