2012-12-21 73 views
0

我正在使用jQuery數據表來顯示客戶記錄。我第一次進入客戶頁面時,我有20個客戶記錄dataTable按 排序客戶ID列(因此它們從20到1開始,其中20是第20位客戶的ID,第1位是第一位客戶的ID)desc 訂購。第20位客戶顯示在dataTable的頂部。如何在列排序後從jquery dataTable中獲取正確的行數據?

現在如果做低於我的javascript代碼

var customerTable=$('#customer').dataTable();// where customer is the html div associated with dataTable 

var custData = customerTable.fnGetData(18)// it gives me data of 19 row in dataTable(as dataTable index starts from 0) 
// so i get the data of customer having customer id=19 

完全沒有到這裏。

現在我單擊customerId列上的排序圖標。因此,在對客戶進行ID分類之後,在dataTable中顯示1,ID爲20的客戶將顯示在底部。現在我做我的JavaScript調度研究再次

var customerTable=$('#customer').dataTable(); 

var custData = customerTable.fnGetData(18) 
// it should give me data for customer id=2 Right? but still i am getting the old data i.e customer Data having id=19. 

我沒有得到我爲什麼不選後得到正確的數據?在dataTable 排序後,我應該如何獲得正確的數據和行ID?

+0

你可以在datatables.net查看這個討論 - http://datatables.net/forums/discussion/13315/fngetdata-does-not-return-the-data-in-right-order-after-column-排序在jQuery數據表#Item_6 –

回答

0

我嘗試了幾乎沒有變化的同樣的事情。

首先創建的全局變量來保存表。

var customerTable; 

然後啓動處於預備狀態的對象。

$(document).ready(function() { 
     customerTable = $('#customer').dataTable(); 
}); 

如果您現在整理並獲取數據。你可能會得到你想要的。

var custData = customerTable.fnGetData(18); 

我唯一知道的是我在排序後沒有啓動表格對象。

+0

我已經這樣做,我已經創建customerTable作爲全局變量,但問題仍然存在。 –

+0

奇怪。這對我很好。我認爲你會需要做更多的調試來捕捉變化在哪個階段發生。 –

相關問題