我想在Javascript中創建一個數據分類器函數,將在HTML表格的最後一個值(總計在我的情況下)。但是,Total將按字母順序排序。需要自定義數據分類器與Bootstrap,把最後一個值
這裏是我的Javascript代碼:
function methodNameSorter(a, b) {
// Total must be at very end of the list of methods.
if (a === "Total" && b === "Total") return 0;
if (a === "Total") return 1;
if (b === "Total") return -1;
var result = a.localeCompare(b);
return result;
}
這裏是通過引導使用功能表中的HTML:
<table id="methods-summary-table" class="table table-hover" data-toggle="table" data-sort-name="name" data-sort-order="asc">
<thead>
<tr>
<th data-field="name" data-sortable="true" data-sorter="methodNameSorter">Method name</th>
...
</tr>
...
</thead>
...
</table>
這裏的排序順序我有這個代碼, Total應該在最後但不是:
Login
Logout
Total
Transaction_A
Verify_X
你知道我在做什麼錯嗎?
什麼是 'A' 和 'B'?它們是內在的還是內在的元素?如果它們是元素,則需要使用if(a.innerHTML ==='Total')'而不是 – Shilly
'a'和'b'是單元格的字符串。我可以通過在Chrome開發者工具中進行調試來確認這一點。 – GDICommander
請仔細檢查一下,因爲你的代碼在數組'''Login','Logout','Total','Transaction_A','Verify_X']'上工作,給你的fn進行排序給了我''Login,Logout,Transaction_A, Verify_X,Total「' – Shilly