0

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 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.