Skip to content

Commit c4505cc

Browse files
committed
v1.5.4. added possibility to define a function as an source of items in select filter.
1 parent 44edc91 commit c4505cc

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

ajaxSource.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,25 @@
2828

2929
}
3030
).columnFilter({
31-
aoColumns: [ { type: "text" },
31+
aoColumns: [
32+
{ type: "text" },
3233
{ type: "text" },
3334
{ type: "number-range" },
34-
{ type: "select" }
35+
{ type: "select",
36+
values: function(aoData, oSettings){
37+
var keys = new Array();
38+
var values = new Array()
39+
for(i=0; i<aoData.length; i++){
40+
var item = aoData[i]._aData[3];
41+
if(keys[item]==null){
42+
keys[item] = true;
43+
//values.push(item);
44+
values.push({ value: item, label: 'The ' + item});
45+
}
46+
}
47+
return values;
48+
}
49+
}
3550
]
3651

3752
});

media/js/jquery.dataTables.columnFilter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* File: jquery.dataTables.columnFilter.js
3-
* Version: 1.5.3.
3+
* Version: 1.5.4.
44
* Author: Jovan Popovic
55
*
66
* Copyright 2011-2014 Jovan Popovic, all rights reserved.
@@ -385,25 +385,25 @@
385385

386386
function fnCreateSelect(oTable, aData, bRegex, oSelected) {
387387
var oSettings = oTable.fnSettings();
388-
if (aData == null && oSettings.sAjaxSource != "" && !oSettings.oFeatures.bServerSide) {
388+
if ( (aData == null || typeof(aData) == 'function' ) && oSettings.sAjaxSource != "" && !oSettings.oFeatures.bServerSide) {
389389
// Add a function to the draw callback, which will check for the Ajax data having
390390
// been loaded. Use a closure for the individual column elements that are used to
391391
// built the column filter, since 'i' and 'th' (etc) are locally "global".
392392
oSettings.aoDrawCallback.push({
393393
"fn": (function (iColumn, nTh, sLabel) {
394-
return function () {
394+
return function (oSettings) {
395395
// Only rebuild the select on the second draw - i.e. when the Ajax
396396
// data has been loaded.
397397
if (oSettings.iDraw == 2 && oSettings.sAjaxSource != null && oSettings.sAjaxSource != "" && !oSettings.oFeatures.bServerSide) {
398-
return fnCreateColumnSelect(oTable, null, _fnColumnIndex(iColumn), nTh, sLabel, bRegex, oSelected); //Issue 37
398+
return fnCreateColumnSelect(oTable, aData && aData(oSettings.aoData, oSettings), _fnColumnIndex(iColumn), nTh, sLabel, bRegex, oSelected); //Issue 37
399399
}
400400
};
401401
})(i, th, label),
402402
"sName": "column_filter_" + i
403403
});
404404
}
405405
// Regardless of the Ajax state, build the select on first pass
406-
fnCreateColumnSelect(oTable, aData, _fnColumnIndex(i), th, label, bRegex, oSelected); //Issue 37
406+
fnCreateColumnSelect(oTable, typeof(aData) == 'function' ? null: aData, _fnColumnIndex(i), th, label, bRegex, oSelected); //Issue 37
407407

408408
}
409409

0 commit comments

Comments
 (0)