2016-01-20 26 views
0

我有數據表的複雜標題,並在表初始化之前附加標題行。如何防止數據表更新列標題文本

但是,當從服務器收到數據時,它更新了標題,我不想更新。

<tr role="row" class="header-row first-row-table-header"> 
    <th colspan="6"></th> 
    <th class="dt-center" colspan="1">2015</th> 
    <th class="dt-center" colspan="1">2016</th> 
    <th colspan="2"></th> 
</tr> 
<tr role="row" class="header-row second-row-table-header"> 
    <th>Year</th> 
    <th>Make</th> 
    <th>Model</th> 
    <th>Badge /Series</th> 
    <th>Series</th> 
    <th>Trans.</th> 
    <th>Dec</th> 
    <th>Jan</th> 
    <th>Age. per Period</th> 
    <th>Total</th></tr> 
<tr role="row" class="header-row third-row-table-header summary-header"> 
    <th class="dt-right" colspan="6">Total Per Month</th> 
    <th column-data="Dec 2015"></th> 
    <th column-data="Jan 2016"></th> 
    <th column-data="Average"></th> 
    <th column-data="Total"></th> 
</tr> 

我列定義爲 當數據到達了第一行預計將顯示與列2015年和2016年冠軍標題。不過它顯示'Dec'和'Jan'。 列定義爲那些2列

{ 
    data: "Dec 2015" 
    headerGroup: "Dec 2015" 
    orderable: false 
    targets: 6 
    title: "Dec" 
} 

{ 
     data: "Jan 2016" 
     headerGroup: "Jan 2016" 
     orderable: false 
     targets: 7 
     title: "Jan" 
} 

從服務器數據如下:

{ 
     Average: "1" 
     Badge: "" 
     Dec 2015: "1" 
     Jan 2016: "1" 
     Make: "BMW" 
     Model: "M135i" 
     Series: "F20" 
     Total: "2" 
     Transmission: "Auto" 
     Year: "2012" 
    } 

如何防止改變第一行標題欄文字數據更新後?

PS:這是顯示的問題。由於服務器速度較慢,您可能需要等待一段時間。

http://live.datatables.net/habokasi/4/edit

+0

哪裏是javascript代碼? – ymz

+0

沒什麼特別的。用ajax調用數據表。 –

+0

你不能用javascript標籤標記問題,要求在javascript中修復,同時堅持不要附加連一行代碼... – ymz

回答

0

你需要用與<thead>否則JQuery的數據表的標題行會使用「標題」在columnDef規定。 https://datatables.net/reference/option/columns.title

有關html表格結構的更多信息,請參閱https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table

或者你可以設置你的columnDef正確的標頭標題:

{ 
data: "Dec 2015" 
headerGroup: "Dec 2015" 
orderable: false 
targets: 6 
title: "2015" 

}

+0

我已經在我的html中有thead。這就是爲什麼我把它追加到$('thead')。另外,沒有與第一個標題行關聯的數據,它僅用於表的可讀性。 –

+0

sry再次查看代碼,看起來您正在將標題行附加到''標記。該片段沒有顯示... – Jonathan

+0

更改列def如何:http://live.datatables.net/dojawaqa/1/edit – Jonathan