I'm using jQuery DataTable plugin with columnFilter add-on. Does anyone know how to setup default values for filters? Specifically for combobox (type: "select") flters?
2 Answers
Looks like the author of the columnFilter plugin has updated the code to do exactly this. Release r69 introduces the "selected" keyword to specify the default value which should be selected.
aoColumns: [ { type: "select", values: [ 'Gecko', 'Trident "New"', 'Trident', 'KHTML', 'Misc', 'Presto', 'Webkit', 'Tasman'], selected: 'Misc' },
Check out http://code.google.com/p/jquery-datatables-column-filter/source/detail?r=69&path=/trunk/media/js/jquery.dataTables.columnFilter.js for details of his fix.
Comments
If you want you may use hack method. In jquery.dataTables.columnFilter.js edit function fnCreateSelect and instead:
for (j = 0; j < iLen; j++) {
r += '<option value="' + aData[j] + '">' + aData[j] + '</option>';
}
use:
for (j = 0; j < iLen; j++) {
if(j==X) {
r += '<option selected value="' + aData[j] + '">' + aData[j] + '</option>';
} else r += '<option value="' + aData[j] + '">' + aData[j] + '</option>';
}
X - index number of default selected option. And after selected.change(function ()
add string select.change();