fnFilter issues with a particular column
fnFilter issues with a particular column
I've never used dataTables but got handed a project that is using it and can't figure out why I'm getting weird fnFilter results on a particular category, which just happens to be called "category". I'll work on getting a running version on jsfiddle but just wanted to see if there was anything that was obviously wrong with the setup of the table. All other columns filter fine, except the "categories" column. Below is the .js file followed by the table.
var reportsTable;
$(document).ready(function() {
set_tab('issues');
$('#search_title').keyup(function() {
reportsTable.fnFilter(this.value, 0);
});
$('#search_submit_begin_time').datepicker({
onClose : function (date, picker) {
submit_time_search($(this), $('#search_submit_end_time'));
}
});
$('#search_submit_end_time').datepicker({
onClose : function (date, picker) {
submit_time_search($('#search_submit_begin_time'), $(this));
}
});
function submit_time_search(begElem, endElem) {
var beg = begElem.val();
var end = endElem.val();
reportsTable.fnFilter(beg + ',' + end, 1);
}
$("input[name='search_status']").change(function() {
var statuses = new Array();
$.each($("input[name='search_status']:checked"), function() {
statuses.push($(this).val());
});
if (statuses.length == 0) {
reportsTable.fnFilter('', 2);
}
else {
reportsTable.fnFilter(statuses.join(','), 2);
}
});
$('#search_address').keyup(function() {
reportsTable.fnFilter(this.value, 4);
});
$('#search_city').keyup(function() {
reportsTable.fnFilter(this.value, 5);
});
$('#search_state').keyup(function() {
reportsTable.fnFilter(this.value, 6);
});
$('#search_zipcode').keyup(function() {
reportsTable.fnFilter(this.value, 7);
});
$("input[name='search_category']").change(function() {
var cats = new Array();
$.each($("input[name='search_category']:checked"), function() {
cats.push($(this).val());
});
if (cats.length == 0) {
reportsTable.fnFilter('', 9);
}
else {
reportsTable.fnFilter(cats.join(','), 9);
}
});
reportsTable = $('table#reports_table').dataTable({
"bServerSide" : true,
"sAjaxSource" : issuesTabPath + '/json/reports',
"sAjaxDataProp" : "tableData",
"aoColumns" : [
{
"mData" : 'title',
"sTitle" : 'Title',
"sClass" : 'title-cell',
"bSortable" : true,
"mRender" : function(data, callType, fullData) {
return '' + data + '';
}
},
{
"mData" : 'submitTime',
"sTitle" : 'Submit Time',
"sType" : 'date',
"sClass" : 'submit-time-cell',
"bSortable" : true,
"mRender" : function(data) {
var date = new Date(data);
return date.toLocaleString();
}
},
{
"mData" : 'resolutionStatus',
"bVisible" : false
},
{
"mData" : 'resolutionStatusLabel',
"sTitle" : 'Status',
"sClass" : 'status-cell',
"bSortable" : true,
"bSearchable" : false,
"iDataSort" : 2
},
{
"mData" : 'streetAddress',
"bVisible" : false
},
{
"mData" : 'city',
"bVisible" : false
},
{
"mData" : 'stateProvince',
"bVisible" : false
},
{
"mData" : 'zipcode',
"bVisible" : false
},
{
"mData" : null,
"sTitle" : 'Address',
"sClass" : 'status-cell',
"bSortable" : true,
"bSearchable" : false,
"iDataSort" : 4,
"mRender" : function(data, callType, fullData) {
return fullData['streetAddress'] + '
' +
fullData['city'] + ', ' + fullData['stateProvince'] + ' ' + fullData['zipcode'];
}
},
{
"mData" : 'category',
"sTitle" : 'Category',
"sClass" : 'category-cell',
"bSortable" : true
},
{
"mData" : 'image',
"sTitle" : 'Image',
"sClass" : 'image-cell',
"bSortable" : false,
"bSearchable" : false,
"mRender" : function(data, callType, fullData) {
return '';
}
}
],
"aoSearchCols" : [
{ "sSearch" : $('#search_title').val() },
{ "sSearch" : $('#search_submit_begin_time').val() + ',' + $('#search_submit_end_time').val() },
{ "sSearch" : ($('#search_status').val() == null) ? '' : $('#search_status').val().join(',') },
null,
{ "sSearch" : $('#search_address').val() },
{ "sSearch" : $('#search_city').val() },
{ "sSearch" : $('#search_state').val() },
{ "sSearch" : $('#search_zipcode').val() },
{ "sSearch" : ($('#search_category').val() == null) ? '' : $('#search_category').val().join(',') }
],
"bLengthChange" : false,
"bFilter" : true,
"bSortCellsTop" : true,
"bProcessing" : true,
"sDom" : 'lrtip',
"fnServerData" : function(sSource, aoData, fnCallback) {
window.clearTimeout(timer);
timer = window.setTimeout(function() {
$.getJSON(sSource, aoData, function(json) {
fnCallback(json);
});
}, delay);
}
});
});
var delay = 750;
var timer;
function submit_query() {
$.getJSON(issuesTabPath + '/json/reportsMatching',
$('#reportCriteriaForm').serialize(),
function(data, status) {
alert("return " + data.success + ": " + data.message);
});
}
function toggle_criteria() {
$('.report_criteria_toggle').toggle();
$('#report_criteria_div').slideToggle();
}
function clear_all_fields() {
$('form#reportCriteriaForm input').val('');
$('form#reportCriteriaForm select').val([]);
for (var i=0; i<10; i++) {
reportsTable.fnFilter('', i);
}
}
function edit_report(id) {
$('#tab-content').load(issuesTabPath + '/report/' + id);
}
var reportsTable;
$(document).ready(function() {
set_tab('issues');
$('#search_title').keyup(function() {
reportsTable.fnFilter(this.value, 0);
});
$('#search_submit_begin_time').datepicker({
onClose : function (date, picker) {
submit_time_search($(this), $('#search_submit_end_time'));
}
});
$('#search_submit_end_time').datepicker({
onClose : function (date, picker) {
submit_time_search($('#search_submit_begin_time'), $(this));
}
});
function submit_time_search(begElem, endElem) {
var beg = begElem.val();
var end = endElem.val();
reportsTable.fnFilter(beg + ',' + end, 1);
}
$("input[name='search_status']").change(function() {
var statuses = new Array();
$.each($("input[name='search_status']:checked"), function() {
statuses.push($(this).val());
});
if (statuses.length == 0) {
reportsTable.fnFilter('', 2);
}
else {
reportsTable.fnFilter(statuses.join(','), 2);
}
});
$('#search_address').keyup(function() {
reportsTable.fnFilter(this.value, 4);
});
$('#search_city').keyup(function() {
reportsTable.fnFilter(this.value, 5);
});
$('#search_state').keyup(function() {
reportsTable.fnFilter(this.value, 6);
});
$('#search_zipcode').keyup(function() {
reportsTable.fnFilter(this.value, 7);
});
$("input[name='search_category']").change(function() {
var cats = new Array();
$.each($("input[name='search_category']:checked"), function() {
cats.push($(this).val());
});
if (cats.length == 0) {
reportsTable.fnFilter('', 9);
}
else {
reportsTable.fnFilter(cats.join(','), 9);
}
});
reportsTable = $('table#reports_table').dataTable({
"bServerSide" : true,
"sAjaxSource" : issuesTabPath + '/json/reports',
"sAjaxDataProp" : "tableData",
"aoColumns" : [
{
"mData" : 'title',
"sTitle" : 'Title',
"sClass" : 'title-cell',
"bSortable" : true,
"mRender" : function(data, callType, fullData) {
return '' + data + '';
}
},
{
"mData" : 'submitTime',
"sTitle" : 'Submit Time',
"sType" : 'date',
"sClass" : 'submit-time-cell',
"bSortable" : true,
"mRender" : function(data) {
var date = new Date(data);
return date.toLocaleString();
}
},
{
"mData" : 'resolutionStatus',
"bVisible" : false
},
{
"mData" : 'resolutionStatusLabel',
"sTitle" : 'Status',
"sClass" : 'status-cell',
"bSortable" : true,
"bSearchable" : false,
"iDataSort" : 2
},
{
"mData" : 'streetAddress',
"bVisible" : false
},
{
"mData" : 'city',
"bVisible" : false
},
{
"mData" : 'stateProvince',
"bVisible" : false
},
{
"mData" : 'zipcode',
"bVisible" : false
},
{
"mData" : null,
"sTitle" : 'Address',
"sClass" : 'status-cell',
"bSortable" : true,
"bSearchable" : false,
"iDataSort" : 4,
"mRender" : function(data, callType, fullData) {
return fullData['streetAddress'] + '
' +
fullData['city'] + ', ' + fullData['stateProvince'] + ' ' + fullData['zipcode'];
}
},
{
"mData" : 'category',
"sTitle" : 'Category',
"sClass" : 'category-cell',
"bSortable" : true
},
{
"mData" : 'image',
"sTitle" : 'Image',
"sClass" : 'image-cell',
"bSortable" : false,
"bSearchable" : false,
"mRender" : function(data, callType, fullData) {
return '';
}
}
],
"aoSearchCols" : [
{ "sSearch" : $('#search_title').val() },
{ "sSearch" : $('#search_submit_begin_time').val() + ',' + $('#search_submit_end_time').val() },
{ "sSearch" : ($('#search_status').val() == null) ? '' : $('#search_status').val().join(',') },
null,
{ "sSearch" : $('#search_address').val() },
{ "sSearch" : $('#search_city').val() },
{ "sSearch" : $('#search_state').val() },
{ "sSearch" : $('#search_zipcode').val() },
{ "sSearch" : ($('#search_category').val() == null) ? '' : $('#search_category').val().join(',') }
],
"bLengthChange" : false,
"bFilter" : true,
"bSortCellsTop" : true,
"bProcessing" : true,
"sDom" : 'lrtip',
"fnServerData" : function(sSource, aoData, fnCallback) {
window.clearTimeout(timer);
timer = window.setTimeout(function() {
$.getJSON(sSource, aoData, function(json) {
fnCallback(json);
});
}, delay);
}
});
});
var delay = 750;
var timer;
function submit_query() {
$.getJSON(issuesTabPath + '/json/reportsMatching',
$('#reportCriteriaForm').serialize(),
function(data, status) {
alert("return " + data.success + ": " + data.message);
});
}
function toggle_criteria() {
$('.report_criteria_toggle').toggle();
$('#report_criteria_div').slideToggle();
}
function clear_all_fields() {
$('form#reportCriteriaForm input').val('');
$('form#reportCriteriaForm select').val([]);
for (var i=0; i<10; i++) {
reportsTable.fnFilter('', i);
}
}
function edit_report(id) {
$('#tab-content').load(issuesTabPath + '/report/' + id);
}
This discussion has been closed.
Replies
Filtering is being done entirely at the server-side if you have server-side processing enabled. So its in your `reports` script that something is going wrong with the filtering, rather than in DataTables itself.
Sorry I can't be of more help since I don't know that script, but helpfully it will point you in the right direction!
Allan
It passes the filter request through to the server as described here: http://datatables.net/usage/server-side . With server-side processing, the processing is done at the server, including filtering :-)
Allan