這是一個相當容易的任務,如果它僅僅是如何計算的某些值的數量爲特定列。你甚至可以實現它作爲一個插件:
jQuery.fn.dataTable.Api.register('countValue()', function(index, value) {
var count = 0;
var data = this.data();
for (var d in data) {
if (data[d][index] == value) count++
}
return count;
});
現在你可以做
console.log('Developer', table.countValue(2, 'Developer'));
console.log('Regional Marketing', table.countValue(2, 'Regional Marketing'));
console.log('Software Engineer', table.countValue(2, 'Software Engineer'));
演示 - >http://jsfiddle.net/hmwLw2yw/
如果您使用的是JSON源,也可能是AJAX請求,請參閱項屬性名稱而不是數組索引:
console.log('Developer', table.countValue('position', 'Developer'));
console.log('Regional Marketing', table.countValue('position', 'Regional Marketing'));
console.log('Software Engineer', table.countValue('position', 'Software Engineer'));
演示 - >http://jsfiddle.net/ytw647ak/
你是如何拉動你的信息?爲什麼你不能這樣做,而不是當你處理前端? – NoReceipt4Panda
它來自我無法控制的預定義報告 – pee2pee
您正在處理哪些語言?你打算用jQuery/js來做這件事嗎? – NoReceipt4Panda