2012-08-24 16 views
1
function fncFadeRowIntoTable(pTable,pColumn,pValue, pHtml) { 
// Add a row to a table in the correct place, by comparing the contents of the column passed (starts 0). 
// This assumes that the table is already sorted 
var counter = 0; // so we know when we've reached the end 
// 
pValue = rtrim(pValue); 

$('#'+pTable).find('tbody tr').each(function() { 
    counter++; 
    if (rtrim($(this).find('td:eq('+pColumn+')').attr('id')) == pValue) { 
    // Have we found a cell equal to the the value passed. If so, then remove the row and replace 
     var $wsRow = $(pHtml); 
     $wsRow.hide(); 
     $(this).fadeOut(1000,function() { 
      $wsRow.insertAfter($(this)).hide(); 
      $(this).remove(); 
      $wsRow.fadeIn(1000).css('display', 'table-row'); 
     }); 
     return false; // break out of each() since we're done 
    } 
    if (rtrim($(this).find('td:eq('+pColumn+')').attr('id')) >= pValue) { 
    // Have we found a cell greater than the value passed 
     var $wsRow = $(pHtml); 
     $wsRow.hide(); 
     $(this).before($wsRow); 
     $wsRow.fadeIn(1000).css('display', 'table-row'); 
     return false; // break out of each() since we're done 
    } 
    // Handle case where we've reached the end, but we're still in the loop. 
    // This means the new row is alphabetically last, so insert after 
    if ($(this).closest('#'+pTable).find('tbody tr').length === counter) { 
     var $wsRow = $(pHtml); 
     $wsRow.hide(); 
     $(this).after($wsRow); 
     $wsRow.fadeIn(1000).css('display', 'table-row'); 
    } 
}); 
// Handle empty table; 
if ($('#'+pTable).find('tbody tr').size() == 0) { 
     var $wsRow = $(pHtml); 
     $wsRow.hide(); 
     $wsRow.appendTo('#'+pTable+' tbody'); 
     $wsRow.fadeIn(1000).css('display', 'table-row'); 
} 
} 

我有一個函數,我用它來更新表中的行,根據匹配單元格的內容。它將插入一個新行或更新現有行。jquery:找到表格行,淡出然後淡入

的部分上面並替換它匹配的行的。我想要實現的是現有的行首先淡出,然後淡出的新行。

我得到的是新行可以直接看到,然後舊行淡出。 .hide()看起來並不有效,但是,我知道插入行時.hide()正在工作。

我已經試過.hide()單獨作爲 $ wsRow.hide(); 也作爲: $ wsRow.insertAfter($(this))。hide(); 或如上所示,在兩個地方。

任何想法我做錯了請。

注意:
pHtml是一個完整的行;即「tr .../tr」數據。

+0

我已經糾正了函數中的上述代碼。原始代碼在錯誤的地方有'return false'(它在fadeout的回調函數中)。該函數允許通過將列的id與傳遞給函數的值進行匹配,將行淡入表中。如果它與一個ID匹配,則該行將被更新的值替換。可以很容易地修改爲使用.html()而不是.attr('id')來匹配單元格內容。 – Keith

+0

由於這對其他人沒有實際價值,請刪除您的這個問題。 (點擊上面的「刪除」鏈接,在「編輯」等附近) –

+0

@凱斯,你可以把它變成答案,並接受它嗎?儘管實際的錯誤可能對許多人沒有幫助,但我首先希望看到問題標題的答案。 – Cullub

回答

0

您的代碼適用於Chrome和IE8中的我,現有行淡出,然後新行淡入 - http://jsfiddle.net/x3JYz/1/

你有可能被interferring任何其他代碼?