Reputation: 4886
I have created a application with dataTable with fixed headers and sorting, the application is working fine but the issue is that I am having a name filtering through a drop-down, which is not working when I select a particular name.
My code is given below.
Can anyone please tell me some solution for this:
$(document).ready(function () {
myTable = $('#myTable').dataTable({
"bInfo": false,
"bLengthChange": false,
"bPaginate": false,
"scrollY": "300px",
"scrollX": "100%",
"scrollCollapse": true,
});
new $.fn.dataTable.FixedColumns(myTable, {
leftColumns: 1,
rightColumns: 1
});
$("#name").on('change', function () {
filterNames();
});
function filterNames() {
var name = $('#name option:selected').attr('value');
myTable.fnFilter(name, 14, false, false, false, false);
}
});
Upvotes: 2
Views: 228
Reputation: 2582
You have entered wrong index in fnFilter
. Find the below working code,
The issue was with on
event, you should provide the selector to on
function
or else use
Delegate: It just attaches the event runtime. For more info refer http://api.jquery.com/delegate/
and
Need to use $(this) to get the selected value inside the event handler.
Upvotes: 3