2015-10-20 96 views
1

如何讓每個列的搜索/過濾器工作?datatables +每列添加一個過濾器

我正在建造一些小步驟,並且不斷地添加到我的數據表中,這個數據表在這個階段非常動態。它基本上建立一個基於數據的數據表。我現在添加了頁腳作爲搜索/過濾器,但不幸的是,這是我陷入困境的地方。我無法讓文件管理器工作。建議非常感謝。

這裏是我的http://live.datatables.net/qociwesi/2/edit

工作我的樣本數據表,它基本上有一個建立由表dTableControl對象。

要建立我的表,我需要調用loadDataFromSocket其執行以下操作:

//then I have this function for loading my data and creating my tables 
//file is an array of objects 
//formatFunc is a function that formats the data in the data table, and is stored in options for passing to the dTableControl for formatting the datatable - not using this in this example 
//ch gets the keys from file[0] which will be the channel headers 
//then I add the headers 
//then I add the footers 
//then I create the table 
//then i build the rows using the correct values from file 
//then I draw and this then draws all the row that were built 
//now the tricky part of applying the search to each columns 

所以我有遠了這一點,但每列搜索無法正常工作。我如何獲得搜索/過濾器每列可用?

注意這是一個非常基本的工作的例子,我已經工作過:http://jsfiddle.net/HattrickNZ/t12w3a65/

回答

0

您應該使用t1.oTable訪問數據表API,請參閱updated example示範。

請將您的代碼與您的問題中的jsFiddle進行比較,注意其簡單性並考慮重新編寫代碼。

+0

tks,你能詳細說明爲什麼我應該重寫。 jsfiddle的例子是一個靜態表,數據表工作,而我的例子是動態的,並能夠繪製給它的東西。這是probs爲什麼它更復雜。你的迴應將不勝感激,因爲我只是一個新手! – HattrickNZ

+0

@HattrickNZ,雖然你的代碼允許你動態構建表,但我認爲你的代碼是不必要的複雜。這將導致未來維護中的錯誤和問題。代碼複雜性很可能是你錯誤地使用't1'而不是't1.oTable'的原因。 –

+0

tks但更具體地說是'dTableControl'對象構建數據表的複雜部分或'loadDataFromSocket'函數?或者它是一個組合? tks的建議,我會看到我可以如何簡化它。 – HattrickNZ